2014-02-13 55 views
2

我有一個ID列可以包含重複項的表,因爲它用作外鍵來匹配我的主表。可以有每個ID多個結果,如下面的例子:合併ID重複的列的值

ID  FieldValue 
1  This 
2  Also this 
1  and that 
3  And additionally, this. 
2  and, finally, this. 

我怎麼會去合併fieldValue方法列,以便有每個ID只有一排?例如。

ID  FieldValue 
1  This;and that 
2  Also this;and, finally, this. 
3  And additionally, this. 

我不會擔心是否重複的行必須保留,例如,

ID  FieldValue 
1  This;and that 
2  Also this;and, finally, this. 
1  This;and that 
3  And additionally, this. 
2  Also this;and, finally, this. 

正如我可以只運行在他們DISTINCT查詢現在,他們是真正的重複。谷歌搜索一段時間沒有結果;我懷疑這是因爲它有幾個步驟,我需要知道這些步驟在搜索之前是多麼富有成效。

任何想法?

+1

謝謝,@GordThompson,這是解決它。我說錯了,但是會在這裏留下這個問題,以防其他人也說錯了! – BFWebAdmin

回答

0

如果你正在使用MySQL,你可以嘗試這樣的事:

SELECT GROUP_CONCAT(FiledValue) As Result FROM tablename WHERE ID= '1' 
+0

嗨 - 謝謝,但它是按標籤訪問的。 – BFWebAdmin