, wenn ich diese beiden Tabellen haben:aus, und alle Zeilen in einer anderen Tabelle
[ id - title - content ]
[ 1 - title1 - content1 ]
[ 2 - title2 - content2 ]
und
[ id - pid - tags ]
[ 1 - 1 - TAG1 ]
[ 2 - 1 - TAG2 ]
[ 3 - 1 - TAG3 ]
[ 4 - 2 - TAG2 ]
Nun, was ich versuche, die title
zu tun ist, wählen und content
von table1
dann alle tags
von table2
wo b.pid = a.id
so meine Frage ist
SELECT a.title, a.content, b.tags
FROM table1 a LEFT JOIN table2 b ON a.id = b.pid
WHERE a.id = 1
, was ich will bekommen, ist
title1 content1 TAG1 TAG2 TAG3
aber was ich bekommen ist nur TAG1
und wiederholte Werte von title1 content1
für jeden Tag
Dann habe ich versucht,
SELECT a.title, a.content,
(SELECT DISTINCT b.tags)
FROM table1 a LEFT JOIN table2 b
WHERE a.id = 1
funktionieren aber immer noch nicht wie beabsichtigt.
Sie haben zwei _tables_, nicht _databases_. – jarlh
@jarlh ich "behoben", dass beim Ändern der Codezeilen in Blöcke –