Welcome to WebmasterWorld Guest from 54.226.130.194

Forum Moderators: open

Message Too Old, No Replies

Query Table While Excluding Other Table's Matches

     

ocon

5:52 pm on Jun 3, 2013 (gmt 0)

5+ Year Member Top Contributors Of The Month



I have two tables:

places:
id = unique, key
name = place name
neighborhood = neighborhood of the place
city = city of the place
country = country of the place

flags:
id = unique, key

Currently I am running a query on the places table:

SELECT * FROM places WHERE (neighborhood="" OR city="" OR country="") LIMIT 5;

How can I modify my query to exclude any rows with their id on the flags table?

LifeinAsia

7:11 pm on Jun 3, 2013 (gmt 0)

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



The following should work:
SELECT p.*
FROM places p LEFT OUTER JOIN flags f ON p.id=f.id
WHERE (p.neighborhood="" OR p.city="" OR p.country="") AND f.id IS NULL
LIMIT 5;