tobeyt23 Posted January 17, 2006 Share Posted January 17, 2006 I am trying to pull only the zips that there ids are not in the zip_tracker table, but when i do so it only sees the first enter that is in the zip_tracker table and show the rest along with everything else that should be shown. The purpose is someone looks up a zip selects it and i place it in the zip_tracker table so when someone else looks up the zip again they can not select it. What is wrong with this:[code]SELECT zip_code.* FROM zip_code RIGHT JOIN zip_tracker on zip_code.zip_code_id!=zip_tracker.zip_code_id and zip_tracker.mailer_date='0000-00-00' WHERE zip_code LIKE '0%'[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted January 17, 2006 Share Posted January 17, 2006 First, you want a LEFT JOIN, not a RIGHT JOIN. Second, if you want records that do _not_ show up in the "right" table, you need to add a "WHERE rightTable.id IS NULL". Third, you'd need to change your ON clause to have an equality relating the primary key to the foreign key. Fourth, I'm not sure what you mean by the first number -- that's in your WHERE clause already.The following query (UNTESTED) will find the "non-tracked" zip codes:[code]SELECT zip_code.* FROM zip_code LEFT JOIN zip_tracker ON zip_code.zip_code_id=zip_tracker.zip_code_id WHERE zip_tracker.zip_code_id IS NULL[/code]Feel free to add whatever other clauses are necessary. Quote Link to comment Share on other sites More sharing options...
tobeyt23 Posted January 17, 2006 Author Share Posted January 17, 2006 thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.