I have a table called user_meta and it contains data like:
---------------------------
| user_id | field | value |
---------------------------
| 1 | 1 | Green |
| 1 | 2 | Square |
| 1 | 3 | Big |
| 2 | 1 | Red |
| 2 | 2 | Square |
| 2 | 3 | Small |
----------------------------
The field column is the number of a form field in the user’s profile. The value column is the value the user submitted via the form.
How do I write a MySQL query that returns all users who have ‘green big squares’?
Thanks!
This will return the result that you want. This uses a
WHEREclause to return all records that have the values that you want, then you count the distinct values to make sure there are only 3:See SQL Fiddle with Demo