id | name | number | address
--------------+------------------+---------+-------------------------------------
1 | channel A | 0 | http://stream01
2 | channel B | 2 | http://stream02
3 | channel C | 16 | http://stream03
4 | channel B | 2 | http://stream04
5 | channel B | 16 | http://stream05
6 | channel C | 16 | http://stream06
7 | channel A | 7 | http://stream07
8 | channel A | 5 | http://stream08
9 | channel A | 0 | http://stream09
...etc
我想刪除重複的頻道(行具有相同的名稱和號碼)。但我希望結果包含其他列以及名稱和編號。
問題是我選擇了哪一個id
和address
刪除了重複項。我很高興選擇它找到的第一個。因此,舉例來說,從上表的結果應該是
id | name | number | address
--------------+------------------+---------+-------------------------------------
1 | channel A | 0 | http://stream01
2 | channel B | 2 | http://stream02
3 | channel C | 16 | http://stream03
5 | channel B | 16 | http://stream05
7 | channel A | 7 | http://stream07
8 | channel A | 5 | http://stream08
...etc
我意識到我可能會在我的查詢需要SELECT name,number FROM table GROUP BY name,number
和查詢應該開始SELECT id,name,number,address FROM (..)
但我想不出辦法在一個查詢中執行此操作。
任何想法?
隨着「刪除」你的意思是你想刪除行或只是沒有他們的結果? – 2012-03-08 14:08:50
沒有他們的結果。有一種感覺,我幾乎擁有它 - 「SELECT ID,名稱,編號,地址從表AS AS JOIN(選擇名稱,號碼FROM表GROUP BY名稱,編號)AS j USING(name,number)'。沒有工作。 – tbh1 2012-03-08 14:15:19