MySQL - Find rows matching all rows from joined table

后端 未结 3 345
無奈伤痛
無奈伤痛 2021-01-27 12:36

Table 1: Tracks

Table 2: Wordlist

Table 3: N:M Track has Words (trackwords)

Find all tracks which have all the words.

currently the query looks l

3条回答
  •  故里飘歌
    2021-01-27 12:55

    Would probably be faster if you broke this up into two queries. First, a join of the words and trackwords to net you all the trackids you need. Then go back to the track table and do:

    WHERE t.id IN(...trackids here...)
    

    but based on the query above all you're returning is t.id which you have from tw.trackid already.

提交回复
热议问题