Join using combined conditions on one join table
- by Nathan Wienert
I have join a table joining songs to genres. The table has a 'source' column that's used to identify where the genre was found. Genres are found from blogs, artists, tags, and posts.
So,
songs | song_genre | genres
id | song_id, source, genre_id | id
What I want to build is a song SELECT query that works something like this, given I already have a genre_id:
IF exists song_genre with source='artist' AND a song_genre with source='blog'
OR exists song_genre with source='artist' AND a song_genre with source='post'
OR exists song_genre with source='tag'
I'm was going to do it by doing a bunch of joins, but am sure I'm not doing it very well.
Using Postgres 9.1.