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
 General SQL Server Forums
 New to SQL Server Programming
 Update & inner join how?

Author  Topic 

ann06
Posting Yak Master

171 Posts

Posted - 2008-04-23 : 09:42:49
Best Greetings,

i want to make an update query for a table but the where clause will check a join with other talbe

update table1 inner join table 2 on x.table1=y.table2 and y.table1= y.table2
set z='anything'

or shall it be


update table1
set z='anything'
where x in (select x from table2) and y in (select y from table2)

i dont know how the syntax be any idea plz ,also table 2 it will be derived from table1 in the form of

select x,max(y)
from table1
order by x




visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-23 : 09:46:40
[code]update t1
set t1.z='anything'
from table1 t1
inner join (select x,max(y) as y
from table1
group by x) t2
on t1.x=t2.x
and t1.y= t2.y[/code]
Go to Top of Page

ann06
Posting Yak Master

171 Posts

Posted - 2008-04-23 : 09:56:47
Thanks pro
Best Regards
Go to Top of Page
   

- Advertisement -