对不起问这样一个新手问题,但我一直在试图理解这个SQL查询并添加一个东西,我不能做到这一点。如何在sql查询中使用两个连接?语法
下面是该查询:
select
p.id, p.nick, p.creation_date
from
tb_player p
left outer join
tb_invoice i on (i.player_id = p.id), tb_player_last_login tpl
where
p.creation_date < now() - '12 months'::interval
and tpl.last_login_date < now() - '12 months'::interval
and tpl.player_id = p.id
and p.id > 9999
and (p.email = 'EDITE-SEU-EMAIL' or p.email = 'configure-seu-email')
and i.id is null
limit 15000;
所以我从这个tb_player
选择一组的人,我有另一个表称为tb_email_list
,我需要的地方说包括具有的tb_player
球员相同的电子邮件地址tb_email_list
有效。
tb_player
有缺口和电子邮件阵营tb_email_list
player_id,电子邮件,is_valid
我试图把一些加入,但没有我这样做似乎工作...
有一点帮助请?
我的朋友帮我,它会像
select p.id, p.nick, p.creation_date
from tb_player_last_login tpl, tb_player p
left outer join tb_invoice i on (i.player_id = p.id)
left join tb_email_list e on e.player_id = p.id
where p.creation_date < now() - '12 months'::interval
and tpl.last_login_date < now() - '12 months'::interval
and tpl.player_id = p.id
and p.id > 9999
and (p.email = 'EDITE-SEU-EMAIL' or p.email = 'configure-seu-email' or e.is_valid = -1)
and i.id is null
limit 15000
感谢您的帮助
您不应该突然混合使用*适当* ANSI JOIN('INNER JOIN','LEFT OUTER JOIN')与旧的,不推荐的*逗号分隔的列表* JOIN的样式 - 使用** 1 **样式(最好是**显式** JOIN关键字!)并坚持下去!在查询 – 2014-09-29 16:35:22