Welcome to WebmasterWorld Guest from 54.205.108.212

Forum Moderators: open

Message Too Old, No Replies

Fill a newly added column with ref number

Depending on parent id

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

Full Member

10+ Year Member

joined:Sept 24, 2002
posts: 214
votes: 0


I have 2 tables

ParentID,
Title,
Etc....

ChildID,
ParentID,
Ref,
Name,
etc...

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)

Senior Member from US 

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 9, 2003
posts:3416
votes: 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)

Full Member

10+ Year Member

joined:Sept 24, 2002
posts: 214
votes: 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.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members