Der er ingen mening i venstre joins, hvis du kun leder efter numre, der har alle ordene. Jeg antager, at (trackid
,wordid
) kombination er unik i trackwords
.
SELECT t.id
FROM track as t, trackwords as tw, wordlist as wl
WHERE t.id=tw.trackid
AND wl.id=tw.wordid
AND wl.trackusecount>0 /* not sure what that is - you have it in your query */
AND wl.word in ('folsom','prison','blues')
GROUP by t.id
HAVING count(*) = 3
Denne forespørgsel ville drage fordel af indekser på wordlist(word), trackwords(trackid,wordid) og track(id).