我有一個MySQL表設置像這樣:GROUP_CONCAT和DISTINCT都很棒,但我如何擺脫這些重複我仍然有?
id uid keywords -- --- --- 1 20 corporate 2 20 corporate,business,strategy 3 20 corporate,bowser 4 20 flowers 5 20 battleship,corporate,dungeon
我想我的輸出看起來像爲:
20 corporate,business,strategy,bowser,flowers,battleship,dungeon
,但我已經得到最接近的是:
SELECT DISTINCT uid, GROUP_CONCAT(DISTINCT keywords ORDER BY keywords DESC) AS keywords FROM mytable WHERE uid !=0 GROUP BY uid
其中輸出:
20 corporate,corporate,business,strategy,corporate,bowser,flowers,battleship,corporate,dungeon
有沒有人有解決方案?感謝提前一噸!
感謝球員,我忘了提及避免大量額外的代碼(包括搜索的東西),我想盡量保持結構,如果可能的話。 – taber 2009-10-15 05:00:32