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

What is a partition function in sql server?

535


How to download and install the scaled-down database adventureworkslt?

606


How to round a numeric value to a specific precision?

569


Is the log file is a part of file group?

549


Is it possible to create trigger on views?

547






can a database be shrunk with users active? : Sql server administration

565


What are the character string functions supported by sql server 2005?

516


List out the difference between union and union all in sql server?

517


What is page in sql server?

513


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

526


Is it true, that there is no difference between a rule and a check constraint?

521


What is candidate key with example?

512


What can be used instead of trigger?

620


Explain different types of index?

590


can any body tell me how to know the password of current user in sql server

1579