Tell me how to create an auto_incrymental column in the table by group?

Example:

id name group_field 1 test 1 2 test2 1 1 test3 2 2 test4 2 1 test5 3 2 test6 3 

The id sequence goes within each group. Found a solution for the table on the MyISAM engine, but I need a solution for InnoDB.

  • I'm only afraid of the tigger with storing the last id for each group in a separate table - Mike
  • @Mike, why a separate table? - Qwertiy
  • @Qwertiy Most databases have problems reading the table on which the trigger is made in the body of the trigger itself. MySQL can and can be but any rake with this I usually fear - Mike

1 answer 1

Useless. Autoincrement basically does not guarantee that the indices will go in a row, which means you can not bother and do autoincrement, independent of the groups.