的所有行,如果我有这两个表:选择一个表中的一行,而在另一张表
[ id - title - content ]
[ 1 - title1 - content1 ]
[ 2 - title2 - content2 ]
和
[ id - pid - tags ]
[ 1 - 1 - TAG1 ]
[ 2 - 1 - TAG2 ]
[ 3 - 1 - TAG3 ]
[ 4 - 2 - TAG2 ]
现在我想要做的是选择title
和content
从table1
然后从table2
所有tags
其中b.pid = a.id
所以我的查询是
SELECT a.title, a.content, b.tags
FROM table1 a LEFT JOIN table2 b ON a.id = b.pid
WHERE a.id = 1
我想要得到的是
title1 content1 TAG1 TAG2 TAG3
但我所得到的仅仅是TAG1
并为每个标签
然后我试图
SELECT a.title, a.content,
(SELECT DISTINCT b.tags)
FROM table1 a LEFT JOIN table2 b
WHERE a.id = 1
的title1 content1
重复值但仍然无法按预期工作。
你有两个_tables_,而不是_databases_。 – jarlh
@jarlh我“固定”,虽然将代码行更改为块 –