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


Please Help Members By Posting Answers For Below Questions

List out the difference between union and union all in sql server?

517


What is the difference between getdate and sysdatetime?

533


What are 3 ways to get a count of the number of records in a table?

609


Explain full-text indexing?

514


What is raid, and how it can influence database performance?

576






Does union all remove duplicates?

607


How to create an multi-statement table-valued function?

526


Explain the commands in sql server?

548


Do you know what is raid and what are different types of raid configurations? : SQL Server Architecture

541


Define model database?

575


Explain the types of indexes.

635


How to drop an existing stored procedure in ms sql server?

542


What are the diifferences between the ms sql server vs mysql?

653


What is merge join?

570


explain extended properties

560