What boolean operator do I want to use in this mysql statement?
5 answers
It is not a question of the "best" way - only the first one works. Even though you want option = ans and option = quest in your result set, the WHERE clause is executed once per line. So you tell MySQL "give me a line where option = quest and option = ans" ie option is two values at the same time, which is impossible. You really want to get strings where either is true, which is why you are using OR
.
I think this reads better:
SELECT * FROM tablename WHERE option IN('ans','quest');
+4
a source to share
This selection will return all whos options lines, ans
orquest
SELECT * FROM tablename WHERE option='ans' OR option='quest'";
This selection, on the other hand, will not return rows as the column only has one of these values
SELECT * FROM tablename WHERE option='ans' AND option='quest'";
+1
a source to share