我尝试在三张桌子上执行连接,但我很震惊
这里条件是 id = 0 和 test =0 和 data =0
每个表将有不同的列数
我想在三个表中选择 a、b、c。
提前致谢
如果我明白这个问题,说实话我不明白,你在寻找工会吗?
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
编辑2您需要在每个联合之前添加 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
我在您的表格中看不到任何关系,那么您如何使用联接?如果您只想显示所有表中的 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