Use this code to delete. DELETE tFROM YourTable tINNER JOIN(SELECT ord_type ord_no item_no line_seq_no FROM YourTable WHERE cd_tp IN (1,3) GROUP BY ord_type ord_no item_no line_seq_no HAVING COUNT(DISTINCT cd_tp)=2)tmpON t.ord_type = tmp.ord_typeAND t.ord_no = tmp.ord_noAND t.item_no = tmp.item_noAND t.line_seq_no = tmp.line_seq_noWHERE t.cd_tp=3
b/w can i ask why you want this deletion to be done in trigger?do you want the deletion to be done at the time the record with cd_tp is inserted into table? Then i think you can have an INSTEAD OF INSERT TRIGGER which checks for presence of a record with all the field value for cd_tp=1 and if it exists it wont insert otherwise it will.something like CREATE TRIGGER YourTrigger ON YourTableINSTEAD OF INSERTASIF NOT EXISTS(SELECT 1 FROM YourTable t INNER JOIN INSERTED i ON t.ord_type = i.ord_type AND t.ord_no = i.ord_no AND t.item_no = i.item_no AND t.line_seq_no = i.line_seq_no WHERE t.cd_tp=1 AND i.cd_tp=3)INSERT INTO YourTableSELECT ord_type, ord_no, item_no, line_seq_no, cd_tpFROM INSERTEDGO