问题
Further to my previous question, this table (expanded from the last question) contains duplicate rows
titel | interpret | jahr
-----------------------------------+------------------+-----
Beauty | Ryuichi Sakamoto | 1990
Goodbye Country (Hello Nightclub) | Groove Armada | 2001
Glee | Bran Van 3000 | 1997
Glee | Bran Van 3000 | 1997
Beauty | Ryuichi Sakamoto | 1990
Goodbye Country (Hello Nightclub)| Groove Armada | 2001
Glee | Groove Armada | 2001
how would I SELECT to get one example of each set of duplicate rows? (the final row consists entirely of duplicate columns, but is not a duplicate row).
I.E, the result would return
| Beauty | Ryuichi Sakamoto | 1990
| Goodbye Country (Hello Nightclub) | Groove Armada | 2001
| Glee | Bran Van 3000 | 1997
回答1:
You would do:
select distinct titel, interpret, jahr from tablename
To get the edited result, you could do something rather interesting like this:
select *
from table1
where rowid in
(
-- get the first row of each distinct titel
select min(sr)
from
(select distinct titel from table1) a
inner join
(
-- get first row number for each distinct titel/interpret/jahr
select min(rowid) as sr, titel, interpret, jahr
from table1
group by titel, interpret, jahr
) b
on a.titel = b.titel
group by
a.titel
);
Results would look like this:
titel |interpret |jahr
Beauty |Ryuichi Sakamoto|1990
Goodbye Country (Hello Nightclub)|Groove Armada |2001
Glee |Bran Van 3000 |1997
来源:https://stackoverflow.com/questions/18680809/my-table-contains-duplicate-rows-how-to-show-one