Hi all, I need your help.
I have an insert query which insert a few rows into the table A.
TableA has two primary keys, which are fieldA and fieldB.
The SQL is written as follows:
INSERT INTO TableA (fieldA , fieldB, fieldC, fieldD)
SELECT DISTINCTROW TableB.fieldA, TableB.fieldB, TableB.fieldC, TableB.fieldD FROM TableB
The problem is that SELECT statement from TableB produces a duplicate combination of fieldA and fieldB. for example.
fieldA fieldB fieldC fieldD
1 1 3 4
1 1 2 5
1 2 5 6
Therefore I have an error when I try to run this insert statement.
What should I do to avoid this to happen?
I just want one row for any duplicate primary keys and I am not fussy. I just don't want this error to pop up.
the result that I desire will be something like
fieldA fieldB fieldC fieldD
1 1 3 4
1 2 5 6
Thank you so much, I really appreciate your help.