MySQL 左连接/WHERE
我将我的地址簿加入到我的电子邮件表中,如下所示:
SELECT * FROM messages m
LEFT JOIN addr_book a ON
m.to_msg LIKE a.h_email
OR m.to_msg LIKE a.bill_email
OR m.to_msg LIKE a.b_email
OR m.to_msg LIKE a.w_email
OR m.to_msg LIKE a.other_email
OR m.from_msg LIKE a.h_email
OR m.from_msg LIKE a.bill_email
OR m.from_msg LIKE a.b_email
OR m.from_msg LIKE a.w_email
OR m.from_msg LIKE a.other_email
OR m.cc_msg LIKE a.h_email
OR m.cc_msg LIKE a.bill_email
OR m.cc_msg LIKE a.b_email
OR m.cc_msg LIKE a.w_email
OR m.cc_msg LIKE a.other_email
OR m.bcc_msg LIKE a.h_email
OR m.bcc_msg LIKE a.bill_email
OR m.bcc_msg LIKE a.b_email
OR m.bcc_msg LIKE a.w_email
OR m.bcc_msg LIKE a.other_email
是它会获取所有内容,因为某些联系人没有电子邮件,并且会加入没有 cc_msg='' 或 bcc_msg='' 的电子邮件
问题 我可以在列上左连接一个表,其中该列类似于“@”?
我尝试了一些诸如 IN (m.to_message LIKE a.h_email WHERE a.h_email LIKE '%@%') OR
等
但我不断收到错误。
有什么想法吗?
非常感谢!
I am joining my address book onto my email table like this:
SELECT * FROM messages m
LEFT JOIN addr_book a ON
m.to_msg LIKE a.h_email
OR m.to_msg LIKE a.bill_email
OR m.to_msg LIKE a.b_email
OR m.to_msg LIKE a.w_email
OR m.to_msg LIKE a.other_email
OR m.from_msg LIKE a.h_email
OR m.from_msg LIKE a.bill_email
OR m.from_msg LIKE a.b_email
OR m.from_msg LIKE a.w_email
OR m.from_msg LIKE a.other_email
OR m.cc_msg LIKE a.h_email
OR m.cc_msg LIKE a.bill_email
OR m.cc_msg LIKE a.b_email
OR m.cc_msg LIKE a.w_email
OR m.cc_msg LIKE a.other_email
OR m.bcc_msg LIKE a.h_email
OR m.bcc_msg LIKE a.bill_email
OR m.bcc_msg LIKE a.b_email
OR m.bcc_msg LIKE a.w_email
OR m.bcc_msg LIKE a.other_email
The problem is it fetches everything, because some contacts don't have emails and join up with emails that don't have cc_msg='' or bcc_msg=''
Is there a way I can left join a table on a column where the column is like '@'??
I tried a couple things like IN (m.to_message LIKE a.h_email WHERE a.h_email LIKE '%@%') OR
etc etc
But I keep getting errors.
Any ideas?
Thanks a ton!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我理解你的问题,你需要使用 AND 而不是 WHERE:
我认为你可能意味着
=
而不是 LIKE 对于第一个测试,这会给出这个:或者也许你只需要这个:
与 LIKE 不同,如果
a.h_email
为空但m.to_message
非空,则相等性测试将失败。If I understand your question, you need to use AND instead of WHERE:
I think you might mean
=
instead of LIKE for the first test, which would give this:Or perhaps you just need this:
Unlike LIKE, an equality test will fail if
a.h_email
is empty butm.to_message
is non-empty.好的,这很有帮助。我不知道为什么,但我一直假设 = 在 mySQL 中区分大小写。我使用了以下内容,效果非常好。谢谢大家,我确信如果我接受过适当的培训,我一开始就不会犯这个错误,哈哈。
Ok so that helps out alot. I don't know why, but I have always assumed = is case sensitive in mySQL. I used the following and it works beautifully. Thanks all, I'm sure if I had proper training I wouldn't have made this mistake in the first place lol.