显示一个表中没有id号的值

时间:2014-11-27 05:12:48

标签: mysql sql join

我现在已经有一段时间没有解决方案了。我尝试过类似的代码,类似的问题仍然没有结果。

我有2个表,其中id列彼此链接。在第二个表上,将id分配给产品项。 第一个表上的id列不必具有与第二个表上的项相关联的每个id。

如何编写查询以显示第一个表中未列出的项目 我试过了

Select items
From product join shop
Where product.productid != shop.productid;

也尝试了这个

Select productid from product
Where productid not in (select productid from shop);

没有运气,我正在使用MySQL。

1 个答案:

答案 0 :(得分:1)

你的第二个解决方案应该有效。 。 。除非shop.productid具有NULL值。试试这个:

Select productid
from product
Where productid not in (select productid from shop where productid is not null);