我的SQL SELECT语句在三个表上JOIN [英] My sql SELECT statement JOIN on three tables

查看:466
本文介绍了我的SQL SELECT语句在三个表上JOIN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在三张桌子上执行联接,但是我很震惊

I tried performing join on three tables but i'm struck

这里的条件将是id = 0且test = 0且data = 0

Here where condition would be id = 0 and test =0 and data =0

每个表的列数都不同

我想在所有三个表中选择a,b,c.

I want to select a,b,c in al three tables.

预先感谢

推荐答案

如果我理解这个问题,说实话我不是,那么您是否正在寻找工会?

If I undertsand the question, which to be honest I don't, are you looking for a union?

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子句

edit2 You will need to add the where clause before each union

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

这篇关于我的SQL SELECT语句在三个表上JOIN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆