homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

Fill a newly added column with ref number
Depending on parent id

 10:23 am on Jan 5, 2010 (gmt 0)

I have 2 tables



I have just added a ref column to allow me to reorder the list of child entries.

What I want to do for the existing data is update the new ref column.

So if there are 10 child items where the parent ID is 1 they the ref column to 1,2,3,...10.

if there are 5 child items with the parent ID of 2 they need to have the ref column set to 1,2,3,4,5

Any suggestions for a query to do this?

Thanks in advance



 9:21 pm on Mar 26, 2010 (gmt 0)

I can't think of a method to do this using SQL alone. It would be pretty trivial to write a script that loops through and updates the records though.


 9:30 pm on Mar 26, 2010 (gmt 0)

Thanks for your reply. I did manage to do it with sql in the insert query I first us a select query to find the highest ref number for a given parent id then use that to insert the new row in the child table.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved