Falundrim Falundrim - 4 months ago 6
SQL Question

How can i create a "twin" of a row and update just one value

i have a little problem here.

I need to create 10 or more rows which are identically and then update just one column.

I will try a schema for my explanation.

I have this :

IDARRET LBL MODELE
1 Car Ford
2 TRUCK Ford
3 Boat Ford


And i want something like this :

IDARRET LBL MODELE
1 Car Ford
2 TRUCK Ford
3 Boat Ford
4 Car Ferrari
5 Truck Ferrari
6 Boat Ferrari


I want it dynamic because i have more than 3 rows.

Sorry for my english, it's not my mother tongue, if you don't understand what i'm saying, please say it to me , i need to improve my englisk skill!

EDIT : After the question of axel : yes idarret is a sequence, i need to create a twin of all my rows and i choose the last value of the last column in my request.

Answer

It seems you simply nou need an insert-select:

SQL> select * from test_twin;

   IDARRET LBL        MODELE
---------- ---------- ----------
         1 Car        Ford
         2 TRUCK      Ford
         3 Boat       Ford

SQL> insert into test_twin
  2  select yourSequence.nextVal, LBL, 'Ferrari'
  3  from test_twin;

3 rows created.

SQL> select * from test_twin;

   IDARRET LBL        MODELE
---------- ---------- ----------
         4 Car        Ferrari
         5 TRUCK      Ferrari
         6 Boat       Ferrari
         1 Car        Ford
         2 TRUCK      Ford
         3 Boat       Ford

6 rows selected.