Jump to content

My Sql Can't Find Not Equal To Data


floridaflatlander

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/269940-my-sql-cant-find-not-equal-to-data/
Share on other sites

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.