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

What do you mean by an execution plan? How would you view it?

469


What is bcp? When does it use?

491


List the types of recovery model available in sql server?

482


What is truncate table?

525


Which tools are available to manage SQL Azure databases and servers?

93






Is it possible to import data directly from t-sql commands without using sql server integration services? If so, what are the commands?

830


How do I completely remove sql server instance?

538


I have triggers,views,functions,stored Procedures for a table. When I am dropping that table which objects are deleted?

577


What do you understand by physical_only option in dbcc checkdb?

557


Explain four layers of abstraction microsoft architectured?

120


What are the types of subquery?

526


What are the events recorded in a transaction log?

485


What is the use of custom fields in report?

540


What is a collation?

564


explain the storage models of olap? : Sql server database administration

494