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 create a new table in a given schema?
Relational calculus is what type of language?
Why de-normalization required?
How to read data in a table with "select" statements?
Do you know what is recursion? Is it possible for a stored procedure to call itself or recursive stored procedure?
How does stuff differ from the replace function?
How does SSIS(Sql Server Integration Services) deffer from DTS(Data Transformation Services)?
How to loop through result set objects using odbc_fetch_row()?
Where are stored procedures in sql server?
Explain what are magic tables in sql server?
How you trouble shoot when any job fails
Is sql server free?
How to select some specific rows from a table in ms sql server?
Explain indexes disadvantages?
What is the report model project?