Subject Re: [firebird-support] Copying rows into tables
Author Paul Vinkenoog
Hi yaedos2000,

Still busy copying those rows? ;-)

> I'm trying to develop an executable procedure for copying a
> specified row from one table to another. So far I've got the
> following:
>
> INSERT INTO TABLE_2 SELECT * FROM TABLE_1 WHERE ID = :SOMETHING;
>
> This works fine if ID is a primary key, as only one result is
> returned. However, ID isn't necessarily unique and there could be
> multiple rows returned. How could the above statement be re-written
> to take account of this?

That depends on what you really want:

- If you want all the matching rows copied, don't change the statement.

- If your criteria are more strict than just the ID value, change the
WHERE clause accordingly. e.g:

WHERE (ID = :THIS) AND (FIELD1 = :THAT) AND (NUM between :A and :B)

- If there may be more rows meeting your WHERE criteria but you only
want one - and you don't care which one - change the SELECT part to:

... SELECT FIRST 1 * FROM ...


Greetings,
Paul Vinkenoog