php - mysql select relation two items
299
Categories
id -- PK
pid -- FK to self (id), allow NULL
name
description
slug
Tags
id -- PK
name
description
slug
Cat_Rel
id -- PK
pid -- FK: Post Id
cid -- FK: Category Id
Tag_Rel
id -- PK
pid -- FK: Post Id
tid -- FK: Tag Id
I need this result in one query: row : pid | tag1,tag2,tag3 | cat1,cat5
Answer
Solution:
I would do this with two subqueries and
union all
:This will ensure that you get all posts, even those with no tags and/or no categories.