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 set a database state to offline in ms sql server?
Are resultset updatable?
Where is localdb stored?
How to generate create table script on an existing table in ms sql server?
How to access the deleted record of an event?
How do I view views in sql server?
Can we use trigger new in before insert?
What is a dbms wizard?
What is a trigger what are the advantages of trigger?
How to add the custom code in Report?
What is a fill factor?
Explain what is “asynchronous” communication in sql server service broker?
What is a database in ms sql server?
How we can refresh the view?
How the authentication mode can be changed?