我有这个问题:
SELECT * FROM
dispensaries_list_new d JOIN cities c ON d.city = c.city_name
AND d.state = c.state_code
我想取所有行,不包括此查询的结果。我试过不等于。但返回错误数据。
答案 0 :(得分:0)
如果您想让不拥有匹配城市的药房,那么您可以使用left join
和where
:
SELECT d.*
FROM dispensaries_list_new d LEFT JOIN
cities c
ON d.city = c.city_name AND d.state = c.state_code
WHERE c.city_name IS NULL;
实际上,如果你想要没有药房的城市,那么你可以使用逆逻辑 - 基本上颠倒了连接的顺序:
SELECT c.*
FROM cities c LEFT JOIN
dispensaries_list_new d
ON d.city = c.city_name AND d.state = c.state_code
WHERE d.city IS NULL;