mysql - Select on join table with exact number of itmes -


i have 2 tables

  • tracks
  • tags

one track have many tags

i want have list of tracks have both of 2 tags example tag_id 1 , tag_id 2

select * tracks  left join tags on tracks.tag_id = tags.id tags.id in (1,2) group track.id having count(tags.id) = 2 

the problem if tracks have tag 1 , 3 listed.

any please?

add distinct count

select track.id tracks  left join tags on tracks.tag_id = tags.id tags.id in (1,2) group track.id having count(distinct tags.id) = 2 

you can change left join inner join since converted implicitly based on clause


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -