mysql mehrere Zeilen markieren mit GROUP CONCAT und MITMACHEN
hier ist ein problem, das ich habe gekämpft, mit.
Ich muss ziehen alle Beiträge ein spesific blog-ID. Zusätzlich muss ich ziehen alle tags, die gehört zu jedem post.
Das problem ist, dass wenn ein post keine tags die query doens nicht zurück. Wie bekomme ich ein leeres Ergebnis für die tags Zelle anstelle des nicht returing der Reihe?
Ich haben die folgenden Tabellen
Beiträge:
ID title
74 HELLO
75 HELLO2
76 HELLO3
tags_relation:
ID|post_id|tag_id
57 74 3
56 74 61
58 75 62
59 75 63
tags:
ID tag
3 Love
61 Sometag
62 Sometag1
63 Sometag2
64 Sometag3
65 Sometag4
Und hier ist meine Abfrage:
SELECT post . * ,
user.username,
user.picture,
GROUP_CONCAT(tag.tag SEPARATOR ',') AS tags
FROM `posts` AS post
INNER JOIN `users` AS USER ON USER.blog_id = post.blog_id
INNER JOIN `tags_relation` AS tags_relation
INNER JOIN `tags` AS tag ON tag.ID = tags_relation.tag_id
WHERE post.blog_id =1
AND post.status = 'publish'
AND post.ID = tags_relation.post_id
GROUP BY post.ID
ORDER BY post.timestamp DESC LIMIT 0,10;
InformationsquelleAutor Ron | 2013-09-21
Du musst angemeldet sein, um einen Kommentar abzugeben.
Versuchen Sie dies:
Sie haben redundante Prädikat in
where
Klauselp.ID = tr.post_id
. Ich habe es entfernt.InformationsquelleAutor Hamlet Hakobyan