我在mysql中编写了一个查询来过滤掉这些供应商'它们不在userid = 1的vendorids中,但它们存在于userid = 5的vendorids中,但我没有得到正确的答案,查询在下面
select vendorid
from rating_table
where (userid = 5) not in (select vendorid from rating_table where userid = 1)
order by vendorid asc;
谢谢
答案 0 :(得分:2)
您需要检查子查询结果中是否不存在vendorid
SELECT vendorid
FROM rating_table
WHERE (userid = 5)
AND vendorid NOT IN
(
SELECT
vendorid
FROM rating_table
WHERE userid = 1
)
ORDER BY vendorid ASC;