I have table named 'Fruit' with 5 columns ('fruit_id', 'name', 'color', 'size', 'weight') where 'fruit_id' is AUTOINCREMENTED. In this table I have 3 entries:
- 1, Apple, Red, Medium, 1.0
- 2, Banana, Yellow, Small, 0.5
- 3, Pear, Green, Large, 2.0
Of which, I only want to copy the following selected fields from row 2 (Banana, Yellow, 0.5) into another table named 'Shipment' which has 5 columns ('ship_id', 'name', 'color', 'price', 'weight').
I don't want to enforce any foreign key relationship between the two tables as I will be deleting the entry from 'Fruits' after the selected fields have been copied into 'Shipment'. Here's what I have so far:
INSERT INTO "Shipment" ("name", "color", "price", "weight") SELECT "name", "color", "weight" FROM "Fruit";
DELETE FROM "Fruit" WHERE "fruit_id" = 2;
But it's giving errors.
Also is there a more elegant method to combine the INSERT and DELETE together into one statement?