如何用sql语句合并三张表
表a表b表ciddata1notes1iddata2notes2iddata3notes30113254601857647897901789978024560287998...
表a 表b 表c
id data1 notes1 id data2 notes2 id data3 notes3
01 132 546 01 85764 78979 01 789 978
02 456 02 879 987 02 897 23
生成表c
ID data1 notes1 data2 note2 data3 note3
01 132 546 85764 78979 789 978
02 456 879 987 897 23
谢谢各位大侠了 展开
id data1 notes1 id data2 notes2 id data3 notes3
01 132 546 01 85764 78979 01 789 978
02 456 02 879 987 02 897 23
生成表c
ID data1 notes1 data2 note2 data3 note3
01 132 546 85764 78979 789 978
02 456 879 987 897 23
谢谢各位大侠了 展开
3个回答
展开全部
select a.id, a.data1, a.notes1, b.data2, b.note2, c.data3, c.notes3
into x
from a,b,c
where a.id = b.id and a.id = c.id
这样三张表的数据就都放在表x里了
注意是在表x不存在的情况下
存在的话这样
insert into x
select a.id, a.data1, a.notes1, b.data2, b.note2, c.data3, c.notes3
from a,b,c
where a.id = b.id and a.id = c.id
into x
from a,b,c
where a.id = b.id and a.id = c.id
这样三张表的数据就都放在表x里了
注意是在表x不存在的情况下
存在的话这样
insert into x
select a.id, a.data1, a.notes1, b.data2, b.note2, c.data3, c.notes3
from a,b,c
where a.id = b.id and a.id = c.id
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select a.id,a.data1,a.notes1,b.data2,b.notes2,c.data3,c.notes3
from 表a
left join 表b on a.id=b.id
left join 表c on b.id=c.id
order by id
from 表a
left join 表b on a.id=b.id
left join 表c on b.id=c.id
order by id
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select a.id, a.data1, a.notes1, b.data2, b.note2, c.data3, c.notes3
from 表a a, 表b b, 表c c
where a.id = b.id and a.id = c.id
order by id
from 表a a, 表b b, 表c c
where a.id = b.id and a.id = c.id
order by id
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询