0

I have a table like:

id | link
---------
1  | abc
2  | asd

and link column should contain id, example: 1-abc. id is autoincreament.

I have this sql:

insert into table(link) values('abc');

should I update back the table, or is there a solution to do it in one query?

Elyor
  • 5,396
  • 8
  • 48
  • 76
  • 3
    Do you really need this data stored in the database? Because you could just as easily select this out when you query the table. – Tim Biegeleisen Dec 13 '16 at 04:56
  • Possible duplicate of [How to get the id of an inserted row ON insert?](http://stackoverflow.com/questions/5465890/how-to-get-the-id-of-an-inserted-row-on-insert) – shmosel Dec 13 '16 at 05:02
  • you could use a trigger on the database if you 're running mysql – Peter Chaula Dec 13 '16 at 05:02
  • You could replace the `AUTO_INCREMENT` column with a simulated sequence, using [`LAST_INSERT_ID()`](http://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_last-insert-id). – shmosel Dec 13 '16 at 05:04

1 Answers1

0

I tested it on mysql only and is the kind of inserting values from one table to another table-

INSERT INTO tablename (`link`) SELECT concat(`AUTO_INCREMENT`,'-','abc') FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'yourdbname' AND TABLE_NAME = 'tablename'

this will add your id infront of your table, i don't know whether it will work or not other than mysql, it works fine in mysql

Veshraj Joshi
  • 3,544
  • 3
  • 27
  • 45