I have a table Product
:
Name Description
----------------------
x 1
y 2
z 3
I have another table Producttemp
:
Name Description
------------------
x 1
x 1
x 2
r 3
r 3
z 8
z 8
I need to insert data from Producttemp
into Product
and only that data which is in combination of Name
and Description
.
So as of now x,1
should not be inserted because this combination already exists in Product
table and only (r,1)
and (z,8)
should be inserted and we don't have to insert the duplicate combinations.
I am trying with this query :
create table #vhf (pk_id numeric)
INSERT INTO product (product_name, product_description)
OUTPUT INSERTED.* INTO #vhf
SELECT
temp.product_name,
temp.product_description
FROM
producttemp
WHERE
NOT EXISTS (SELECT distinct temp.product_name FROM product prj, product temp
WHERE temp.product_description = prj.product_description
AND temp.product_name = prj.product_name)
This query is returning all the values that are not there in product table but it is also inserting the duplicate rows