Table genre
id | genre | display
---+-----------+------------
1 | Action | 1
2 | Comedy | 0
3 | Romance | 1
Table movies
id | genre_id | movie | year | display
---+-----------+---------------+---------+------------
1 | 1 | Kill Bill | 2003 | 1
2 | 1 | Die Hard | 1988 | 0
3 | 2 | Anchorman | 2004 | 1
4 | 3 | Titanic | 1997 | 1
5 | 3 | Casablanca | 1942 | 1
Query
SELECT genre.genre, movies.movie, movies.year FROM `genre` JOIN `movies` ON
genre.id = movies.genre_id WHERE genre.display = 1 AND movies.display = 1
I'm trying to write a sql statement so that I get the result below in this specific order. If a genre has a display of 1, then the genre itself will be displayed, as well as any of its movies that have a display of 1. Also, genre names shouldn't be duplicated:
Action
- Kill Bill
- 2003
Romance
- Titanic
- 1997
- Casablanca
- 1942