I'm working with postgreSQL 9.3.
I'd like to say that my question is a bit subjective but I didn't find any related questions or articles...
I have three tables as following:
artists:
+--------+----------+
|artistId| name |
+--------+----------+
| 1 | James |
| 2 | Jack |
| 3 | Henry |
| 4 | Tom |
+--------+----------+
genres:
+---------+-----------+
| genreId | name |
+---------+-----------+
| 1 | rock |
| 2 | dub |
+---------+-----------+
and the junction table artistsGenres:
+--------+---------+
|artistId| genreId |
+--------+---------+
| 1 | 1 |
| 2 | 2 |
| 3 | 1 |
| 4 | 2 |
+--------+---------+
I want to get all the artists by genre name. For the moment I do it like this:
SELECT a.*
FROM artistsGenres aG
INNER JOIN artists a ON a.artistId = aG.artistId
WHERE aG.genreId = (SELECT genreId FROM genres WHERE name = 'dub');
I'm wondering if there is a more efficient way to do it?