sql server - Copy Data from multiple table to one table without duplicate -


i want insert data source (1&2) tables destination table without duplicates

table: source

       songs       artists         album s        baby         john          rocknroll        moon         mike          moonlight        firefly      chad           garden 

table: source2

       songs       artists         albums        happy        jane           fresh        baby         john          rocknroll        bday         zelda           link 

table: destination

id     song       artist         album       catalog#     track#   <--- columns  1     baby        john        rocknroll 

here code:

insert destination      (song,      artist,      album)  select distinct      so.songs,      so.artists,      so.albums,      source  left join destination ds      on ds.song= so.songs      , ds.artist= so.artists      , ds.album= so.albums       ds.song null  , ds.song null  , ds.songis null 

however after trying code on both table still duplicate

i tried union have more 2 source table?

you can union istead of join

insert destination      (song,      artist,      album)  select       so.songs,      so.artists,      so.albums (      select so.songs,             so.artists,             so.albums      source       union       select so.songs,             so.artists,             so.albums      source2       union       select so.songs,             so.artists,             so.albums      source3       union       select so.songs,             so.artists,             so.albums      source4       union       select so.songs,             so.artists,             so.albums      source5       )      ds.song null  , ds.song null  , ds.songis null 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -