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
List the data types available in mssql?
do views contain data ?
What is attribute relationships, why we need it? : sql server analysis services, ssas
How many types of keys are there?
Why use stored procedures in sql server?
What is “begin trans”, “commit tran”, “rollback tran” and “savetran”?
Tell me what are cursors and when they are useful?
Explain how long are locks retained within the repeatable_read and serializable isolation levels, during a read operation with row-level locking?
What is triggers and stored procedures?
What is save transaction and save point?
What is built-in/administrator?
How to delete existing rows in a table?
What are the different types of replication you can set up in sql server?
Explain features of analysis services?
What is a linked server in sql server?