Reputation: 198
I have two tables with city names in them. I want to check the first table against the second table and if the first table does not contain a city name in the second table then select it to display. So if the city is in both tables, then do not display it.
I know that I can do this to find the ones that match:
WHERE table1.city=table2.city
But when I try to use this for things that dont match:
Where table1.city!=table2.city
I still get the cities that match.
Upvotes: 1
Views: 1099
Reputation: 29870
SELECT `city_name`
FROM `first_table`
WHERE `city_name` NOT IN (SELECT `city_name` FROM `second_table`)
Will select city names from the first table that are not in second table.
Upvotes: 1