1

table1

MBID   |    Artist
__________________

123321   The Beatles
123214   Led Zeppelin
123321   The Beatles

如何将所有distinct MBID's及其相应的Artist名称复制到一个新表中,以便新表只有 distinctMBID

 MBID   |    Artist
__________________

123321   The Beatles
123214   Led Zeppelin

我试过了

 insert into table2 (MBID,artist) 
 select distinct(table1.MBID),table1.artist 
 FROM danktable

但这给了我奇怪的组合,而不仅仅是不同的 MBID

当我创建MBID主索引时,此查询出现错误,因为我得到非唯一MBID值。

有人可以帮我吗?

谢谢 !

4

1 回答 1

3

你可以这样做:

 insert into table2 (MBID,artist) 
 select MBID,max(artist)
 from table1
 group by MBID
于 2012-10-09T17:48:28.307 回答