Suppose I have the table
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
I want to remove duplicate channels (rows with the same name and number). But I want the result to contain the other columns along with name and number.
The problem is which id and address I choose once I've removed the duplicates. I'm happy to choose the first it finds. So, for example, the result from the above table should be
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
I realise I'll probably need a SELECT name,number FROM table GROUP BY name,number in my query and the query should start off SELECT id,name,number,address FROM (..) but I just can't think of a way to do this in one query.
Any ideas?
SELECT id,name,number,address FROM table AS t JOIN (SELECT name,number FROM table GROUP BY name,number) AS j USING(name,number). Didn't quite work.