我尝试在三张桌子上进行连接,但我很震惊
此处条件为id = 0且test = 0且data = 0
每个表都有不同的列数
我想在三个表中选择a,b,c。
提前致谢
答案 0 :(得分:0)
如果我遗漏了这个问题,说实话我不知道,你在寻找工会吗?
select a,b,c,0 as e,0 as f, test,data from table1
union
select a,b,c,e,f, test,data from table2
union
select a,b,c,0 as e,0 as f, test,data from table3
编辑包含e和f
edit2 您需要在每个联合之前添加where子句
select a,b,c,0 as e,0 as f, test,data from table1
where test= 1 and data =1 and id =0
union
select a,b,c,e,f, test,data from table2
where test= 1 and data =1 and id =0
union
select a,b,c,0 as e,0 as f, test,data from table3
where test= 1 and data =1 and id =0
答案 1 :(得分:0)
我在表格中看不到任何关系,那么你如何使用加入?如果你只想显示所有表中的a,b和c记录,那么你可以使用UNION。
select a,b,c from tbl_name1
UNION
select a,b,c from tbl_name2
UNION
select a,b,c from tbl_name3