I am using DB2 DBMS.
Scenario 1:
myTable has a composite key (key1, key2) where both key1 and key2 are foreign keys from yourTable.
I want to insert new data from yourTable into myTable, but only if the key1, key2 combination does not already exist in myTable.
insert into myTable(key1, key2, someData)
values(x, y, z)
where NOT EXISTS (want to check if composite key is not already present)
Scenario 2:
I put data into a java object from yourTable with properties data1, data2, and data.
I want to insert the above data with the check as in Scenario1. data1 + data2 should not already be present in myTable.
How do I achieve this? I don't think we can use a SELECT statement inside the insert statement.
insert into myTable(key1, key2, data)
values(data1, data2, data)
where (data1 + data2 are already not present in myTable)
How can I achieve this?