我有3张桌子
1.usertb
email funcarea
2.professiontb
email experience
3.generalinfo
email location
我想使用字段电子邮件将这三个表格合并为3个条件,例如 funarea = 2和体验&gt; = 3和< strong> location ='悉尼'
由于我是SQL的初学者,我很想知道如何实现它。
答案 0 :(得分:1)
select a.email,funarea,experience,location from usertb a
left join professiontb b
on a.email = b.email
left join generalinfo c
on a.email = c.email
where
funarea = 2 and experience >=3 and location = 'Sydney'
答案 1 :(得分:1)
如果每张表中至少有一个条目:
(生硬和愚蠢,但有效)
SELECT *
FROM usertb, professiontb, generalinfo
WHERE usertb.email=professiontb.email AND professiontb.email=generalinfo.email AND usertb.funcarea=2 AND professiontb.experience>=3 AND generalinfo.location='Sydney';
如果每个表中没有一个条目,我的建议是使用LEFT JOIN语句。
SELECT * FROM usertb WHERE usertb.funcarea=2
LEFT JOIN professiontb ON(usertb.email=professiontb.email AND professiontb.experience>=3)
LEFT JOIN generalinfo ON(usertb.email=generalinfo.email AND generalinfo.location='Sydney');
按原样,你应该从usertb获取所有行,即使其他表中有一些缺失的行。