homepage Welcome to WebmasterWorld Guest from 54.224.179.98
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Query Table While Excluding Other Table's Matches
ocon




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

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




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

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;

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved