join - How do you make a condition on a column in one table apply to every instance of a primary key? -
i have table called 'artists' has columns artist_id, artist_name, artist_genre , table called 'albums' artist_id, album_id, album_name, album_number_songs etc.
i join these 2 tables via artist_id. want know artists have never had album on 12 songs. have tried this:
select distinct artist_name artists inner join albums on albums.artist_id=artists.artist_id album_number_songs < 12
however checks instances , output on whether or not album has < 12 not artist overall...does know?
please try query:
select artist_name artists artists.artist_id not in (select albums.artist_id albums albums.artist_id = artists.artist_id , albums.album_number_songs > 12)
this includes artists no albums think corresponds better initial task.
Comments
Post a Comment