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 / swati tripathi

SELECT
OUTERTABLE.EMPID,
MAX(OUTERTABLE.SALARY)

FROM

(SELECT EMPID,MAX(SALARY) AS SALARY
FROM DEP1
GROUP BY EMPID
UNION ALL
SELECT EMPID,MAX(SALARY) AS SALARY
FROM DEP2
GROUP BY EMPID) AS OUTERTABLE
GROUP BY OUTERTABLE.EMPID

Is This Answer Correct ?    8 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Differentiate between mongodb vs. Sql server?

567


Explain what are the events recorded in a transaction log?

537


Explain intellisense for query editing

552


What is buffer cash in sql server?

587


What is a dbms wizard?

599






What is index, cluster index and nonclustered index?

500


What are the differences between local and global temporary tables?

538


Explain what are the basic functions for master, msdb, model, tempdb databases?

519


Explain different types of index?

578


What are the advantages of using stored procedures?

524


What are the different types of locks in the database?

476


How to list all user names in a database?

576


Explain identity in sql server?

548


What is checkpoint in sql server?

599


How to find Duplicate Records In table?

577