how to get the maximum among two tables,for example table 1
(dep1) have (emp_id,emp_name,salary) columns and table 2
(dept2) have (emp_id,emp_name,salary) columns,i want which
employee have the maximum salary among two tables?

Answer Posted / saurabh agrawal

select top 1 empid, empname, max(salary) from (
Select empid, empname, salary = max(salary) from dep1 group
by empid, empname
union all
Select empid, empname, salary = max(salary) from dep2 group
by empid, empname
)A
group by empid, empname order by max(salary) desc

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the advantages of mirroring?

572


Explain stored procedure?

603


How to recompile stored procedure at run time?

569


What is not null constraint?

622


What is dbcc updateusage?

536






Can we make the the chages By Using the Sql if u know any function or process please inform me Actuall result: BRK1 Break 1 Part 1 00:01:00:00 60 BRK1 Break 1 Part 2 00:01:00:00 60 BRK2 Break 2 Part 1 00:01:00:00 60 BRK2 Break 2 Part 2 00:01:00:00 60 BRK2 Break 2 Part 3 00:01:00:00 60 BRK3 Break 3 Part 1 00:01:00:00 60 BRK3 Break 3 Part 2 00:01:00:00 60 Desired O/P: BRK1 Break 1 Part 1 00:01:00:00 60 Part 2 00:01:00:00 60 BRK2 Break 2 Part 1 00:01:00:00 60 Part 2 00:01:00:00 60 Part 3 00:01:00:00 60

1722


What do you understand by physical_only option in dbcc checkdb?

579


What are date and time data types in ms sql server?

529


Tell me what is the stuff and how does it differ from the replace function?

540


How and why use sql server?

548


What is the optimal disk configuration for a database server and what raid configurations would you use if budget is not a constraint?

486


What is the maximum size of a row in sql server?

529


What were the latest updates to SQL Azure service?

94


How to remove duplicate rows from table except one?

576


Can you explain full-text query in sql server?

552