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

List the data types available in mssql?

534


do views contain data ?

592


What is attribute relationships, why we need it? : sql server analysis services, ssas

510


How many types of keys are there?

532


Why use stored procedures in sql server?

559






What is “begin trans”, “commit tran”, “rollback tran” and “savetran”?

594


Tell me what are cursors and when they are useful?

513


Explain how long are locks retained within the repeatable_read and serializable isolation levels, during a read operation with row-level locking?

664


What is triggers and stored procedures?

519


What is save transaction and save point?

630


What is built-in/administrator?

580


How to delete existing rows in a table?

593


What are the different types of replication you can set up in sql server?

531


Explain features of analysis services?

531


What is a linked server in sql server?

581