Arens Myzyri Arens Myzyri - 26 days ago 7
MySQL Question

MySQL best select multi condition query

I have a MySQL query:

SELECT * FROM product_variants WHERE (bottom_type = '$bottom_type1' OR bottom_type = '$bottom_type2' ) AND (bottom_size = '$bottom_size ' ) AND (product_id != '$product_id1 ' OR product_id != '$product_id2' OR product_id != '$product_id3')


It is not working as it should, its not giving me the results needed.
What is the best way to build it?
Thanks

Answer

This is just my guess at what you're after. Example table structure, with data and expected results would help answer your question.

SELECT * 
FROM product_variants 
WHERE bottom_type IN ('$bottom_type1', '$bottom_type2') 
AND bottom_size = '$bottom_size' 
AND product_id NOT IN ('$product_id1 ', '$product_id2', '$product_id3')