Welcome to WebmasterWorld Guest from 54.196.244.45

Forum Moderators: open

Message Too Old, No Replies

can I do a join that shows what is 'not' in the other table?

mysql, query, join

     
7:12 pm on Nov 24, 2010 (gmt 0)

New User

5+ Year Member

joined:Feb 9, 2010
posts: 26
votes: 0


I have two tables connected by 'pid'.
When setting a product up, there is an option to set a tax table. If none is set, the table 'tax' does not get an entry.

Can I use a join to show all pids in 'products' that are not in 'tax', or do I have to build a PHP routine to sift this out?

Thanks!
7:31 pm on Nov 24, 2010 (gmt 0)

Moderator from US 

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

joined:Dec 10, 2005
posts:5550
votes: 24


Yup- LEFT OUTER JOIN is your friend!

Example:
SELECT Table1.pid
FROM Table1 LEFT OUTER JOIN Table2 ON Table1.pid=Table2.pid
WHERE Table2.tax IS NULL
1:03 am on Nov 25, 2010 (gmt 0)

New User

5+ Year Member

joined:Feb 9, 2010
posts: 26
votes: 0


awesome! Thanks so much!