I have three tables tag
, page
, pagetag
With the data below
page
ID NAME
1
Sergio del Amo:
However, I am not getting the pages without tags. I guess i need to write my query with left outer joins.
SELECT pagetag.id, page.name, group_concat(tag.name)
FROM
(
page LEFT JOIN pagetag ON page.id = pagetag.pageid
)
LEFT JOIN tag ON pagetag.tagid = tag.id
GROUP BY page.id;
Not a very pretty query, but should give you what you want - pagetag.id
and group_concat(tag.name)
will be null
for page 4 in the example you've posted above, but the page shall appear in the results.