I need to insert some registers in a table. These registers have three fileds: field1, field2 and field3. I don't want to insert a register if in the table already exists a row with the field2 and field3 combination of that register. And I don't want to declare these fields as key fields. How can I filter a "destination" table by two fields?
I'll appreciate your answer
create table table1(
col1 int not null,
col2 int not null,
col3 int not null,
constraint PK_table1 primary key (col2, col3)
This is my "insert" code:
INSERT INTO table1
SELECT table2.col1,table2.col2, table3.col3
FROM table2, table3
WHERE table2.col1 = table3.col1
If there is already a row in table1 with a combination of table2.col2 and table3.col3, I want my insertion code not to insert the "new" register, the one that has that combination (to avoid repetitions by two fields). Since these are PK fields, I would like to avoid errors. I don't know if this can be done.