24903

Question:
I have table1
, which has
MBID | Artist
__________________
123321 The Beatles
123214 Led Zeppelin
123321 The Beatles
How can I copy all of the <strong>distinct</strong> MBID's
along with their corresponding Artist
name, into a new table, so that the new table only has distinct MBID
's
MBID | Artist
__________________
123321 The Beatles
123214 Led Zeppelin
I've tried
insert into table2 (MBID,artist)
select distinct(table1.MBID),table1.artist
FROM danktable
But this gives me weird combinations and not only distinct MBID's
When I make the MBID
a primary index, I get an error with this query because i'm getting non-unique MBID
values.
Could someone help me out?
Thanks !
Answer1:You can do it as follows :
insert into table2 (MBID,artist)
select MBID,max(artist)
from table1
group by MBID