Question:
In Oracle SQL how can I add all of the rows from one table into another table if both have same exact columns?
biily b
2010-04-27 23:56:01 UTC
I have two tables, Imeem and myspacemusic. Both tables have the columns ( USTID, Track_Title, Artist, Album)

myspacemusic has roughly 15 rows of data, imeem has the exact same 15 rows plus about 5 more

how can i insert the rows from imeem into the myspacemusic and not create duplicate rows so im basically only adding the 5 unique rows and in essence the myspacemusic table will be exactly as the original imeem table was?

any suggestions?
Three answers:
TheMadProfessor
2010-04-28 06:17:56 UTC
Assuming that USTID is the primary key in both tables:



INSERT INTO myspacemusic

SELECT USTID, Track_Title, Artist, Album FROM lmeem

WHERE USTID NOT IN (SELECT USTID FROM myspecemusic)
?
2016-12-04 10:52:31 UTC
you are going to be able to desire to connect on your analyze table two times, which seems atypical. yet think of of it this way, what in case you had 2 analyze tables, one for ID1 and yet another for ID2? Then it could make suited sense to have 2 joins. i could be a tad off on the syntax, yet this could be close. Assuming elect t1.call ID_1, t2.call ID_2 from fieldTable connect lookupTable t1 on t1.identity = fieldTable.ID_1 connect lookupTable t2 on t2.identity = fieldTable.ID_2;
Neeraj Yadav♄
2010-04-28 03:23:20 UTC
Use insert select queries like below



insert into foo

(a,b,c)

(select AA,

BB,

CC

from

(select query with where condition )





Hope this helps

Cheers:)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...