Mysql 我的sql SELECT语句连接三个表

Mysql 我的sql SELECT语句连接三个表,mysql,select,join,Mysql,Select,Join,我试着在三张桌子上表演join,但我被打动了 这里的条件是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 ta

我试着在三张桌子上表演join,但我被打动了

这里的条件是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

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

我在您的表中看不到任何关系,因此如何使用join?如果您只想显示所有表中的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

显示您尝试过的SQL代码,并描述您遇到的困难。您可以在此处发布您编写的查询吗?实际上..我没有看到任何表。表名在哪里?与这3个表有关系吗?我不确定这些表之间的关系。在这种情况下,您可以使用相同的方法选择所有列,并在服务器端脚本上操作所需的列。请参见编辑,已包含e和f,对于表1和表3,我刚刚返回0@Rippo:我让它工作了,现在我如何添加test=1和data=1以及id=0。如果这有帮助,请投票支持我,并将答案标记为接受,谢谢。你可能想接受更多的答案,因为有些人在未来不会以低利率帮助你。。。。Thanks@sujal-这是我答案的直接副本!