gpt4 book ai didi

mysql - 当连接表中不存在值时

转载 作者:行者123 更新时间:2023-11-29 07:22:00 25 4
gpt4 key购买 nike

我使用此查询来查找 users 的电子邮件地址是否不存在于 emails_sent 表中。

SELECT users.email,users.registration_date 
FROM users
LEFT JOIN emails_sent
ON emails_sent.email=users.email
WHERE emails_sent.email IS NULL
ORDER BY registration_date DESC
LIMIT 0,50

相反,我想返回users.email,其中没有emails_sent.type='welcome'

的记录

我尝试了以下方法,但没有返回结果

SELECT users.email,users.registration_date 
FROM users
LEFT JOIN emails_sent
ON emails_sent.email=users.email
WHERE emails_sent.type!='welcome'
ORDER BY registration_date DESC
LIMIT 0,50

emails_sent表如下

id  int(11) unsigned    NO  PRI NULL
email varchar(200) YES NULL
type varchar(200) YES NULL
timestamp int(200) YES NULL

最佳答案

只需在 LEFT-JOIN 部分包含“AND”条件,而不是 WHERE

SELECT 
users.email,
users.registration_date
FROM
users
LEFT JOIN emails_sent
ON users.email = emails_sent.email
AND emails_sent.type = 'welcome'
where
emails_sent.email IS NULL
ORDER BY
registration_date DESC
LIMIT
0,50

因此,您的加入既取决于匹配用户的标准,又取决于“欢迎”电子邮件消息。 Ø

关于mysql - 当连接表中不存在值时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35809531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com