I’m trying to knock the rust off my SQL skills and need some help with the following query. The database i’m currently using is mysql.
I want to retrieve all the FlashCards that are assigned BOTH ‘tag2’ and ‘tag4’. Based on the contents of the existing table (as seen in the excerpt below) the query should return two rows: FlashCard_ID 1 and 2.
How would I formulate this query? It’s been a while since I’ve had to do something like this.
mysql> select * from flashcard;
+--------------+------------+----------+
| FLASHCARD_ID | QUESTION | ANSWER |
+--------------+------------+----------+
| 1 | Question 1 | Answer 1 |
| 2 | Question 2 | Answer 2 |
| 3 | Question 3 | Answer 3 |
+--------------+------------+----------+
3 rows in set (0.00 sec)
mysql> select * from tag;
+--------+------+
| TAG_ID | NAME |
+--------+------+
| 1 | tag1 |
| 2 | tag2 |
| 3 | tag3 |
| 4 | tag4 |
| 5 | tag5 |
+--------+------+
5 rows in set (0.00 sec)
mysql> select * from flashcard_tags;
+--------+--------------+
| TAG_ID | FLASHCARD_ID |
+--------+--------------+
| 2 | 1 |
| 3 | 1 |
| 4 | 1 |
| 2 | 2 |
| 4 | 2 |
| 5 | 2 |
+--------+--------------+
6 rows in set (0.00 sec)
1 Answer