I have the following situation.
Table1
+----+-------------+
| id | name |
+----+-------------+
| 1 | John |
| 2 | Alice |
+----+-------------+
Table2
+----+--------------+--------------+
| id | trait | color |
+----+--------------+--------------+
| 1 | hair | blond |
| 1 | eyes | blue |
| 2 | hair | brown |
| 2 | eyes | blue |
+----+--------------+--------------+
I would like to find the names of everyone who is both blond and blue-eyed in one query. I have tried something like this, but it hasn't worked:
SELECT t1.name FROM table1 as t1, table2 as t2
WHERE
t1.id = t2.id AND
(t2.trait = 'hair' and t2.trait = 'blond') AND
(t2.trait = 'eyes' and t2.trait = 'blue');
I'm of course looking for the most efficient MySQL way to do this.
Edited: Initial question was too simple and did not accurately reflect my situation