SQL: Gather right hand values from a join
- by Max Williams
Let's say a question has many tags, via a join table called taggings. I do a join thus:
SELECT DISTINCT `questions`.id
FROM `questions`
LEFT OUTER JOIN `taggings`
ON `taggings`.taggable_id = `questions`.id
LEFT OUTER JOIN `tags`
ON `tags`.id = `taggings`.tag_id
I want to order the results according to a particular tag name, eg…