I want a mysql query for following scenario
I have following database structure
1] table 'albums' Columns 'id', 'name'
2] table 'tracks' Columns 'id', 'title', 'album_id' (album has many tracks)
3] table 'assets' Columns 'id', 'track_id' (track has many assets)
I want to find out all the albums such that, all the tracks of that album must have at least 2 assets.
For following test data
albums
'id' 'name'
1 Album 1
2 Album 2
tracks
'id' 'title' 'album_id'
1 Track 1 1
2 Track 2 1
3 Track 3 2
4 Track 4 2
assets
'id' 'track_id'
1 1
2 1
3 2
4 2
5 3
6 3
7 4
So my query o/p should be
'id' 'name'
1 Album 1
As Album 1 has two tracks Track 1 and Track 2 and both of these tracks have 2 assets whereas Track 4 of Album 2 have only 1 asset
Try:
SQLFiddle Demo