floridaflatlander Posted October 26, 2012 Share Posted October 26, 2012 I can't figure this out the first sql statement with "=" works fine. The second with "!=" doesn't. This one works, it includes only items whose category is 34 or whose category parent is 34 $q = "SELECT photos.thumb, product.id_prod, product.title, photos.thumb_width, photos.thumb_height FROM product JOIN members ON (product.id_mem = members.id_mem AND mem_group >=1 AND mem_group <100) JOIN category ON (product.id_cat = category.id_cat AND (category.id_parent = '34' OR category.id_cat = '34')) LEFT JOIN photos ON (product.id_prod = photos.id_prod AND photos.main_photo = '1') WHERE product.publish = '1' ORDER BY product.id_prod DESC"; This one doesn't work, it includes all items published, including those whose category is 34 or whose category parent is 34(which it shouldn't) and the statements are almost exactly alike. $q = "SELECT photos.thumb, product.id_prod, product.title, photos.thumb_width, photos.thumb_height FROM product JOIN members ON (product.id_mem = members.id_mem AND mem_group >=1 AND mem_group <100) JOIN category ON (product.id_cat = category.id_cat AND (category.id_parent != '34' OR category.id_cat != '34')) LEFT JOIN photos ON (product.id_prod = photos.id_prod AND photos.main_photo = '1') WHERE product.publish = '1' ORDER BY product.id_prod DESC"; Thanks Quote Link to comment https://forums.phpfreaks.com/topic/269940-my-sql-cant-find-not-equal-to-data/ Share on other sites More sharing options...
Jessica Posted October 26, 2012 Share Posted October 26, 2012 in the second, you probably want to change category.id_parent != '34' OR category.id_cat != '34') to category.id_parent != '34' AND category.id_cat != '34') Quote Link to comment https://forums.phpfreaks.com/topic/269940-my-sql-cant-find-not-equal-to-data/#findComment-1387947 Share on other sites More sharing options...
floridaflatlander Posted October 26, 2012 Author Share Posted October 26, 2012 (edited) Thanks Jessica, that works great, but I don't know why. I would think it would be it would be OR because the category is either a parent or has a parent not both. What am I looking at wrong? Thanks Added Thanks again Jessica, I see it now. Edited October 26, 2012 by floridaflatlander Quote Link to comment https://forums.phpfreaks.com/topic/269940-my-sql-cant-find-not-equal-to-data/#findComment-1387956 Share on other sites More sharing options...
Jessica Posted October 26, 2012 Share Posted October 26, 2012 For anyone else who doesn't get it: OP is working with a negative - If he wants to exclude anything that has one column set to 34, OR a different column set to 34, that means EVERY row which has any value but 34 on BOTH columns. Row Col Col A 31 34 B 34 31 C 31 31 D 34 34 He wants row C. Col1 != 34 AND Col2 != 34. Anything else is not a valid match Quote Link to comment https://forums.phpfreaks.com/topic/269940-my-sql-cant-find-not-equal-to-data/#findComment-1387995 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.