Created
December 15, 2010 18:20
-
-
Save irohiroki/742374 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> select * from items; | |
+------+----+ | |
| name | id | | |
+------+----+ | |
| aaa | 1 | | |
| bbb | 2 | | |
| ccc | 3 | | |
| ddd | 4 | | |
+------+----+ | |
4 rows in set (0.00 sec) | |
mysql> select * from tags; | |
+------+----+ | |
| name | id | | |
+------+----+ | |
| tag1 | 1 | | |
| tag2 | 2 | | |
+------+----+ | |
2 rows in set (0.00 sec) | |
mysql> select * from items_tags; | |
+---------+--------+ | |
| item_id | tag_id | | |
+---------+--------+ | |
| 1 | 1 | | |
| 2 | 1 | | |
| 2 | 2 | | |
| 3 | 2 | | |
+---------+--------+ | |
4 rows in set (0.00 sec) | |
mysql> select i.name, t1.name, t2.name from items i join items_tags it1 on it1.item_id = i.id join tags t1 on it1.tag_id = t1.id join items_tags it2 on it2.item_id = i.id join tags t2 on it2.tag_id = t2.id where t1.name = 'tag1' and t2.name = 'tag2'; | |
+------+------+------+ | |
| name | name | name | | |
+------+------+------+ | |
| bbb | tag1 | tag2 | | |
+------+------+------+ | |
1 row in set (0.00 sec) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment