Home » SQL & PL/SQL » SQL & PL/SQL » Joins
Joins [message #230058] Tue, 10 April 2007 15:29 Go to next message
rudorathod
Messages: 14
Registered: October 2006
Junior Member
I have two tables A and B with same columns

Table A
col1 | col2 | col3
ab | bc | cd
sy | sd |ar

Table B
col1 | col2 | col3
sy | sd |ar

I have a scenario where table A has some records in it and Table B has got some records in it.

I want to insert a row in Table B from Table A if the Table B doesn't have a matching record.
If the record exist it should not insert that record.

so it should only insert
ab | bc | cd

How can I do it using the joins.

Thanks
Re: Joins [message #230059 is a reply to message #230058] Tue, 10 April 2007 15:36 Go to previous messageGo to next message
BlackSwan
Messages: 25046
Registered: January 2009
Location: SoCal
Senior Member
What does your SELECT statement look like to obtain only the rows to be INSERTed?
Re: Joins [message #230060 is a reply to message #230058] Tue, 10 April 2007 15:38 Go to previous messageGo to next message
rudorathod
Messages: 14
Registered: October 2006
Junior Member
something like this

Insert into Table B
select a.col1, a.col2, a.col3 from Table A............
.......rest of the condition between two tables so that it gives only the result"ab | bc | cd"

Thanks
Re: Joins [message #230061 is a reply to message #230058] Tue, 10 April 2007 15:40 Go to previous message
Michel Cadot
Messages: 64131
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
merge into tableb b
using tablea a
on (b.col1=a.col1 and b.col2=a.col2 and b.col3=a.col3)
when not matched then insert values (a.col1,a.col2,a.col3)
/

Regards
Michel

[Updated on: Tue, 10 April 2007 15:40]

Report message to a moderator

Previous Topic: Eliminate Special characters.
Next Topic: cast-ing question
Goto Forum:
  


Current Time: Wed Dec 07 13:04:09 CST 2016

Total time taken to generate the page: 0.13132 seconds