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
What is a partition function in sql server?
How to download and install the scaled-down database adventureworkslt?
How to round a numeric value to a specific precision?
Is the log file is a part of file group?
Is it possible to create trigger on views?
can a database be shrunk with users active? : Sql server administration
What are the character string functions supported by sql server 2005?
List out the difference between union and union all in sql server?
What is page in sql server?
Can you explain how long are locks retained within the repeatable_read and serializable isolation levels, during a read operation with row-level locking?
Is it true, that there is no difference between a rule and a check constraint?
What is candidate key with example?
What can be used instead of trigger?
Explain different types of index?
can any body tell me how to know the password of current user in sql server