You might want to put a unique
contraint on the pair to prevent uniques.
First guesses are operator error or the table already had data. Discounting those, there is another possibility. The types of the fields are:
`CMTE_ID` varchar(9) DEFAULT '',
`TRAN_ID` varchar(32) DEFAULT '',
Perhaps these are not big enough, so the data is actually being truncated when loaded into the table. This is just an idea. Your process seems sound.
EDIT:
Actually, I think the last is what is happening. Your insert
query is equivalent to:
INSERT INTO uniques(CMTE_ID, TRAN_ID)
SELECT TRAN_ID,CMTE_ID
FROM t1
GROUP BY TRAN_ID,CMTE_ID
HAVING count(*) = 1;
Note that the column orders are different, so TRAN_ID
is being loaded into CMTE_ID
and vice versa. Because the types are different, the CMTE_ID
is probably being truncated.
This is a good lesson in why you should always include column lists in insert
statements.