读书人

求一SQL语句!解决办法

发布时间: 2012-03-21 13:33:15 作者: rapoo

求一SQL语句!!
现有两个表,表1为学生表
student
字段为 ID Name Age
表2 为教师表
teacher
字段为 ID Name Age Department等

现欲实现将两个表中的内容整合在一起如
字段为 ID Name
即查询结果中包含所有的教师和学生的ID和Name


[解决办法]
select ID,Name from student
union all
select ID,Name from teacher
[解决办法]
Select ID, Name From student
Union All
Select ID, Name From teacher
[解决办法]
yuxing117(雨行) ( ) 信誉:100 Blog 2007-03-20 11:01:49 得分: 0


想问下楼上的几位哥哥,
如果我想实现查询Teacher表中的所有字段,Student表中无此字段就写入Null值该如何呢?


---------------------
Select ID, Name,Age, Null From student
Union All
Select ID, Name, Age, Department From teacher

读书人网 >SQL Server

热点推荐