【发布时间】:2023-03-03 23:24:01
【问题描述】:
我对 JOINS 没有太多经验,并且通过下面的查询得到的结果不正确。 我有一个名为 products 的表,想检查表 product_links 中是否有记录。 我只想获取 product_links 中没有行的项目列表。
当我运行以下查询时,我只得到一行。 有人建议吗? Google 无法帮助我,或者我使用了错误的关键字进行搜索。
SELECT a.id, a.SKU, a.title,
(SELECT COUNT(b.id) AS amount FROM product_links WHERE b.product=a.id) AS amount
FROM products AS a
LEFT JOIN product_links AS b ON b.product=a.id
【问题讨论】:
-
提示:养成在浏览器中输入问题有意义部分的习惯。例如,输入
mysql get a list of items that doesn't have rows in other table将立即为您提供答案。