|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Insert / Compare on multiple columnsTableA contains customer_number,product_id,purchase_date.
TableB contains customer_number,product_id,purchase_date. I need to insert everything into TableB from TableA where the entire row from TableA (customer_number,product_id,purhase_date) doesn't already exist in TableB (customer_number,product_id,purchase_date). How is this possible? Thank you much. Try:
INSERT tblA ( customer_number,product_id,purchase_date ) SELECT customer_number,product_id,purchase_date FROM tblB WHERE NOT EXISTS ( SELECT * FROM tblA WHERE tblA.customer_number = tblB.customer_number AND tblA.product_id = tblB.product_id AND tblA.purchase_date = tblB.purchase_date ) ; -- Anith use NOT EXISTS
insert into TableB (customer_number, product_id, purchase_date) select customer_number, product_id, purchase_date from TableA a where not exists (select * from TableB where customer_number=a.customer_number and product_id=a.product_id and purchase_date=a.purchase_date) Jay wrote: Show quote >TableA contains customer_number,product_id,purchase_date. >TableB contains customer_number,product_id,purchase_date. > >I need to insert everything into TableB from TableA where the entire row >from TableA (customer_number,product_id,purhase_date) doesn't already exist >in TableB (customer_number,product_id,purchase_date). How is this possible? > >Thank you much. > > > > > > > |
|||||||||||||||||||||||