MySQL query for initial filling of order column

Posted by Sejanus on Stack Overflow See other posts from Stack Overflow or by Sejanus
Published on 2010-04-13T11:15:25Z Indexed on 2010/04/13 12:23 UTC
Read the original article Hit count: 245

Filed under:
|

Sorry for vague question title.

I've got a table containing huge list of, say, products, belonging to different categories. There's a foreign key column indicating which category that particular product belongs to. I.e. in "bananas" row category might be 3 which indicates "fruits".

Now I added additional column "order" which is for display order within that particular category. I need to do initial ordering. Since the list is big, I dont wanna change every row by hand. Is it possible to do with one or two queries? I dont care what initial order is as long as it starts with 1 and goes up.

I cant do something like SET order = id because id counts from 1 up regardless of product category and order must start anew from 1 up for every different category.

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql-query