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 / saurabh agrawal
select top 1 empid, empname, max(salary) from (
Select empid, empname, salary = max(salary) from dep1 group
by empid, empname
union all
Select empid, empname, salary = max(salary) from dep2 group
by empid, empname
)A
group by empid, empname order by max(salary) desc
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What is the difference between a unique key and primary key?
Is null vs coalesce?
How to connect to a sql server using odbc_connect()?
What happens when unicode strings concatenate with non-unicode strings?
Determine when to use stored procedure to complete sql server tasks?
Explain multiserver query
What is Transparent Data Encryption?
Is the log file is a part of file group?
How to find related tables in sql server?
Do you know data definition language, data control language and data manipulation language?
How to call stored procedure using http soap?
what is the main function of a query parameter?
What are system databases into sql server (2005/2008)?
What is the distinction amongst delete and truncate?
What is normalization 1nf 2nf 3nf?