我有sqlite数据库和歌曲表,现在我想从此表中获取艺术家列表,我想删除重复匹配,所以如果我有一个艺术家2或3次,例如我将得到它只有一次,任何方式做到这一点?
我在使用no:
SELECT artist FROM Songs ORDER BY name
答案 0 :(得分:4)
您可以使用distinct
关键字:
select distinct artist from songs order by artist;
或者,如果您想要比艺术家名称多一点(例如,每位艺术家的参赛作品数量),您可以使用group by
条款:
select artist, count(*) as entries from songs group by artist order by artist;
答案 1 :(得分:2)
SELECT DISTINCT artist FROM Songs ORDER BY name
答案 2 :(得分:-1)
DELETE FROM Songs WHERE id NOT IN
(SELECT MAX(id) FROM table GROUP BY id);