Subject Re: [ib-support] SQL query
Author Svein Erling Tysvaer
At 13:10 07.05.2003 +0200, you wrote:
>AFAIK, that insert would fail, and none of the records would be inserted.
>
>One solution would be to create the other table and do:
>INSERT INTO NewTable (column_list)
>SELECT DISTINCT column_list FROM OldTable;

Ah, OK, I spoke too soon - I didn't know since I never create tables
without primary keys.

However, your solution would only work if all columns contained the same
value - and not if the fields contained in the PK were equal whereas the
others differed (leaving the same problem as my original, erroneous
suggestion). Of course, I'm not Alfred and do not know whether this is the
case or not. If they do differ this way, then I'd recommend adding another
(temporary) column, assign a value to this column using a generator and then do

DELETE FROM MyTable A
WHERE EXISTS(SELECT * FROM MyTable B WHERE A.Column1 = B.Column1 AND
A.Column2 = B.Column2 AND A.TemporaryColumn > B.TemporaryColumn)

Of course, if you already do have one column that differ and know which of
the values within this column you want to delete, then you should use this
column rather than a new temporary column.

Set