turpentyne Posted December 1, 2011 Share Posted December 1, 2011 I want to search a database and get items that appear in the connector database twice with either variable 1 or 23. So if I search for any items that have been entered with both 1 and 23 variables, then I want to pull that item's id. AND gives me nothing. OR gives me all the results of 1 and all the results of 23 item_id | variable ------------+---------------- 211924 | 1 ------------+---------------- 211924 | 23 ------------+---------------- This query below gives me no results, when I want to get 1 result: 211924 SELECT item_id FROM `connect_tables` JOIN items ON connect_tables.item_id = items.item_id WHERE connect_tables.term_id LIKE 1 AND connect_tables.item_id LIKE 23 This query gives me every item that has been entered with 23 or 24, not with both. SELECT item_id FROM `connect_tables` JOIN items ON connect_tables.item_id = items.item_id WHERE connect_tables.term_id LIKE 1 OR connect_tables.item_id LIKE 23 I hope that made sense. Quote Link to comment Share on other sites More sharing options...
fenway Posted December 1, 2011 Share Posted December 1, 2011 Don't use "LIKE" when you mean "=" -- that's just confusing. A valid can't be "1" and "23" at the same time -- that's why AND doesn't make any sense. OR will give you either -- hence you're getting both. If you want to find items that have 2 rows -- once with termId 1 and a second time with term_id 23 -- you'll need to join twice. 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.