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 current pricing model of SQL Azure?
Which are the important points to note when multilanguage data is stored in a table?
what's the maximum size of a row? : Sql server database administration
What's new in sql management studio for sql server? : sql server management studio
Find first and last day of current month in sql server
You have modified 100 store procedures and want to replicate these changes from development to prodution, and production can have users using the Server/DB, how would you replicate without causing issues?
Will count(column) include columns with null values in its count?
Explain important index characteristics?
what is the difference between count(*) and count(1) ?
How to update muliple row in single query?
Why union all is faster than union?
How and why use sql server?
What are different replication agents and what's their purpose? : sql server replication
What is the difference between a local and a global temporary table?
what is raid and what are different types of raid configurations? : Sql server database administration