Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Update statement with condition

Author  Topic 

nasty84
Starting Member

6 Posts

Posted - 2010-03-10 : 14:47:41
Table 1
ID ChildID GroupID
101 201 ?
102 201 ?
103 201 ?
Table 2
ChilID GroupID RANK
201 300 1
201 301 2
201 302 3
I nned to populate the groupID in table 1 with rank from table 2.
I.e
ID ChildID GroupID
101 201 300
102 201 301
103 201 302

The lesser the rank goes to first ID of Table1.....second groupid goes to second id of table 1 as rank is 2 in table 2 and so on.
How can i acheive this?
Thanks for your help and time..

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-03-10 : 17:42:52
quote:
I nned to populate the groupID in table 1 with rank from table 2.
I.e
ID ChildID GroupID
101 201 300
102 201 301
103 201 302

Update with column GroupID or Rank from Table 2. The required result shown 300 - 302 is the GroupID of Table 2



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

avijit_mca
Posting Yak Master

109 Posts

Posted - 2010-03-11 : 00:17:41
Hi,

update Table_1 set groupid = (select groupid from Table_2 b where b.id = Table_1.id )

Regards,
avijit
Go to Top of Page
   

- Advertisement -