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 / lince p. thomas

select T.empname,salary from
(
select a.empname as empname ,a.salary as salary from dep1 a
union all
select b.empname as empname,b.salary as salary from dept2 b
)T where T.salary=(select max(T.salary) as salary from
(select max(a.salary) as salary,a.empname as empname
from dep1 a group by a.empname
union all
select max(b.salary)as salary,b.empname as empname from
dept2 b group by b.empname)T
)

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why I have to use stored procedures?

565


I create a separate index on each column of a table. What are the advantages and disadvantages of this approach? : Sql server database administration

550


how you can configure a running aggregate in SSRS?

110


Why do we use functions?

487


What is database replication?

556






Can you explain powershell included in sql server 2008?

485


What is a field in a table?

549


Is it possible to update the views? If yes, how, if not, why?

521


Can you explain what are various ways to enhance the ssrs report?

561


Explain few examples of RDBMS?

592


You want your report to display a hyperlink that will take users to your intranet. How do you configure such a hyperlink?

235


What is the purpose of indexing?

567


Explain how many normalization forms?

558


Do you know what is difference between index seek vs. Index scan?

497


Which are the two editions in which SQL Azure database available?

97