Is there a better way than this?
SELECT * FROM tagcloud
WHERE (usertag_tag = 1
OR usertag_tag = 2
OR usertag_tag = 3
OR usertag_tag = 4)
What if I want to add more tags to the query, do I keep adding OR statements?
Use MySQL IN
SELECT * FROM tagcloud
WHERE (usertag_tag = 1
OR usertag_tag = 2
OR usertag_tag = 3
OR usertag_tag = 4)
/* You are checking whether usertag_tag is either 1, 2, 3 OR 4*/
Is equivalent to:
SELECT * FROM tagcloud
WHERE (usertag_tag IN (1, 2, 3, 4))
/* You are checking usertag_tag is one of the values in the array given as
array(1, 2, 3, 4)
If you want to add more values, just add elements to the array, that is it.
*/
Explanation:
If we are comparing single value, we use =.
If we need to find a rows with given field in one of the values (array of values), we use IN.
MySQL IN functions logically same as PHP's in_array()
usertag_tag !=6usertag_tag IN(1,2,3,4,5)which is standard SQL and will function like anORchain.