From my understanding, IN works like this:
$arrayName = array(1, 2, 3); SELECT * FROM tableName WHERE productID IN ($arrayName)
is equivalent to:
SELECT * FROM tableName WHERE productID = 1 OR productID = 2 OR productID = 3
I am wondering if there is an SQL function that works like IN but uses AND instead of OR to compare with an array. Something that would expand to this:
SELECT * FROM tableName WHERE productID = 1 AND productID = 2 AND productID = 3
Not that it was necessary, but for context, I just create a sort list for some search results that populate on a PHP page through jQuery. I can do what I need with PHP, I just create a query dynamically depending on what parameters the user has chosen, but I would prefer to use the intelligent SQL function, if possible.
*** EDIT: Thank you all for your help. I explained my problem very poorly, and you could still figure it out, which I appreciate. I found that someone even more eloquently asked this question and got an answer that I can use:
Is there something in MySQL like IN but that uses AND instead of OR?
I'm trying to figure out how to accept the answer and close it, but I have problems ...
Bidbits
source share