MySQL 查询 table_b 中而不是 table_a 中的行
我执行此查询是为了获取 table_b 中而不是 table_a 中的行:
SELECT table_b.* FROM table_b
LEFT JOIN table_a ON table_b.id = table_a.id
WHERE table_a.item_id IS NULL
这可以正常工作,但我需要另一个条件来应用于 table_a。我只需要比较 X 列的 ID 等于 3 的行,而不是比较整个表。有什么想法吗?
谢谢。
I'm doing this query to get rows that are in table_b and not in table_a:
SELECT table_b.* FROM table_b
LEFT JOIN table_a ON table_b.id = table_a.id
WHERE table_a.item_id IS NULL
This works ok but I need another condition to apply on table_a. I need to compare only the rows that got column X equal with the ID of 3, not to compare the whole table. Any ideas ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您是否正在寻找 table_a 列 x 或 table_b 列 x,但想法是将其添加到 join ON 子句中:
I'm not sure if you're looking for table_a column x or table_b column x, but the idea is to add that to the join ON clause:
试试这个...
应该可以解决问题...
但这有点奇怪,因为它可能会返回比您需要的更多。此查询还将返回 table_b 中在 table_a 中确实有结果的任何行,但这些行的“X”值不为 3。
如果它不起作用,请尝试为您的数据提供一个示例需要查找您不想要的数据,我们可以尽力提供进一步帮助!
Try this out...
Should do the trick...
But this is a bit strange, as it will probably return more than you require. This query will also return any rows from table_b which do have a result in table_a, but where those rows don't have an 'X' value of 3.
If it doesn't work, please try to give an example for data that you need to find, and data that you don't want, and we can try to help further!