mysql - How to insert the number of id in the neighbor column? -
i have table structure:
+----+-------------------+ | id | identical_with_id | +----+-------------------+ id auto-increment , need insert in column identical_with_id identical value id's value. how can that?
i want this:
+----+-------------------+ | id | identical_with_id | +----+-------------------+ | 1 | 1 | | 2 | 2 | | 3 | 3 | +----+-------------------+ note, in reality table containing other values identical_with_id column, this:
+----+-------------------+ | id | identical_with_id | +----+-------------------+ | 1 | 1 | -- question | 2 | 1 | -- answer of above question | 3 | 1 | -- answer of above question | 4 | 4 | -- question | 5 | 4 | -- answer of above question | 6 | 6 | -- question | 7 | 7 | -- question | 8 | 7 | -- answer of above question | 9 | 7 | -- answer of above question +----+-------------------+ now need insert question in table. , want know how can fill column: identical_with_id ?
no need update table. can in single insert query shown below.
insert `table_name` values(null, (select `auto_increment` information_schema.tables table_schema = 'database_name' , table_name = 'table_name')); although don't see point of doing so...
Comments
Post a Comment