Monday, 15 February 2010

sql - Update statement with self join in sybase -



sql - Update statement with self join in sybase -

i have 1 table contain next data.

emp_id name dept cat 1 abc p 1 hc g 2 def p 2 et g 3 ghi p 3 bc g 3 mn g 4 jkl p 4 ls g 4 ls g

i want update table have output records like.

emp_id name dept cat 1 abc hc p 2 def et p 3 ghi bc p 4 jkl ls p

if emp_id associated 2 different dept should update 1 of dept (emp_id=3). if 1 emp_id associated 2 same dept should come 1 time (emp_id=4). using below query

update table1 set a.dept = b.dept table1 a, table1 b a.emp_id=b.emp_id , a.cat='p'

but not updating emp_id 3 , 4 can help?

thanks, dhiraj

multiple steps psudeo code since don't know sybase syntax enough:

get results you're after in select. select emp_id, max(name), max(dept), max(cat) tablename grouping empi_id

insert results temp table

drop table , recreate temp table.

sql sybase self-join

No comments:

Post a Comment