I’m having some trouble remembering my database queries – it’s been a while 🙁
Let’s say I have some tables:
WORDS {ID, WORD}
FILES {ID, URL}
FILES_WORDS {WORDID, FILEID, COUNT}
WORDS and FILES both have PK’s named ID and a string for their word/path respectively. FILES_WORDS denormaizes the many-to-many relationship and holds the count of times each word appeared in each file.
I know I can select the information for a given file like this:
SELECT FILES.URL, WORDS.WORD, FILES_WORDS.COUNT FROM WORDS, FILES, FILES_WORDS
WHERE FILES_WORDS.FILEID = FILES.ID AND FILES_WORDS.WORDID = WORDS.ID AND
IFILE.ID = 1;
I’m sure there’s a cleaner syntax using joins and things like that though and I’m having trouble googling it or remembering it. Can anyone help speed/clean this up?
I think you are looking for something like this:
But it is not necessarily faster. Depends on volume, indices, etc.
I used aliases (the one letter nickname for the table) because it makes it easier to follow, and I don’t think you need both joins, but that also depends on what you are trying to do.