SELECT table1.value, table2.additionalinfo
FROM table1
LEFT OUTER JOIN table2
ON table1.ID=table2.ID
我尝试输出类似这样的东西
Value AdditionalInfo
blah something, somethingelse, more
blah2 NULL
blah3 stuff
但我得到
Value AdditionalInfo
blah something
blah somethingelse
blah more
blah2 NULL
blah3 stuff
我尝试使用GROUP_CONCAT
和GROUP_CONCAT(DISTINCT)
SELECT GROUP_CONCAT(table1.value), table2.additionalinfo
FROM table1
left outer JOIN table2
ON table1.ID=table2.ID ORDER BY table1.value
当我添加GROUP_CONCAT
和ORDER BY table1.value
时,它会为每个值列出一个附加信息,但没有值,也没有重复的附加信息。我四处移动订单都无济于事。
答案 0 :(得分:0)
我认为您需要在GROUP_CONCAT
列上AdditionalInfo
而不是table1.value
SELECT table1.value,
GROUP_CONCAT(distinct table2.additionalinfo) additionalinfo
FROM table1
left outer JOIN table2 ON table1.ID=table2.ID
GROUP BY table1.value
ORDER BY table1.value