Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nested select and update

Status
Not open for further replies.

bluebytez

Programmer
Dec 20, 2001
39
MY
Hi, I have a problem with a database which I have imported from a text file.
In one of my tables, there are more a few rows for each staff. The problem is, the data for one of the columns ( i.e. Age ) only exists in the first row of the same staff. How do I make a SQL statement to fill the other rows belonging to the same staff with the data from the first row ?
I hope I have not confused anyone.
Thanks for your help !
 

Here is one possibility that may work depending on your RDMS. You may need to modify the Where criteria depending on the contents of the Age column.

Update table
Set Age = b.Age
From table As a
Inner Join
(Select StaffId, Age From table
Where Age Is Not Null) As b
On a.StaffID=b.StaffID
Where a.Age Is Null Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Thanks a lot tlbroadbent, it worked for me !
You are the SQL MAESTRO !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top