Hi,
I needed to come up with a SQL query that returns rows that satisfy multiple conditions. This article describes what I needed to do and the solution: http://thenoyes.com/littlenoise/?p=58
Basically it uses a bit operation to figure out if a provided string is found.. but I'm having hard time following how it works.
SET @q = 'A,B';
SELECT studentName
FROM quizAnswers
GROUP BY studentName
HAVING
BIT_OR(1 << FIND_IN_SET(question, @q) - 1)
=
(1 << LENGTH(@q) - LENGTH(REPLACE(@q, ',', '')) + 1) - 1; -- This is 2^numValues - 1
+-------------+
| studentName |
+-------------+
| seekwill |
+-------------+
I tested it and it works as expected. Can someone explain how this works?
Thanks, Amie