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
How to call a function from a stored procedure in SQL Server ?
What is recursion? Is it possible for a stored procedure to call itself or recursive stored procedure? How many levels of sp nesting are possible?
Explain following error properties?
What do you understand by SQL*Net?
Please explain go command in sql server?
What is tempdb database? : SQL Server Architecture
What is coalesce and check constraint in sql server?
what is nonclustered index
Does union all remove duplicates?
Do you know exporting and importing utility?
How to use order by with union operators in ms sql server?
What is ssl in sql server?
What is difference in performance between insert top (n) into table and using top with insert?
Explain about Views?
What different steps will a sql server developer take to secure sql server?