select teacher_id,teachername ,Longtime ,teacherclass from sys_teacher
union
select student_id,studentname ,Longtime ,studentclass from sys_student
这个是查询出来的 但是我要通过teacher_id,student_id这个两个合并成一个新的表
新建一个表,假设你的表名为table1,它的字段分别为:id, name, Longtime, class
执行下面的sql, 可以将两个旧表的数据保存进新表
INSERT INTO table1
( [id] ,
[name] ,
[Longtime] ,
[class]
)
SELECT teacher_id,
teachername ,
Longtime ,
teacherclass
FROM sys_teacher
UNION
SELECT student_id ,
studentname ,
Longtime ,
studentclass
FROM sys_student
建立一个视图
create view NewTable
as
select teacher_id as ID,teachername ,Longtime ,teacherclass from sys_teacher
union
select student_id as ID,studentname ,Longtime ,studentclass from sys_student
这个是查询出来的 但是我要通过teacher_id,student_id这个两个合并成一个新的表
楼上正解
一楼三楼正解。
不想在数据库里建表的话,可以建个临时表。