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

What are translations and its use? : sql server analysis services, ssas

601


What do you understand by mirroring and mention the advantages of the mirroring?

577


What is advantage data architect?

507


Explain how dts is used to extract, transform and consolidate data?

580


How to create new tables with "select ... Into" statements in ms sql server?

510






Explain about protocol layer present in SQL server?

609


What is an example of a foreign key?

507


What is the main purpose of having conversation group?

496


What is self join in sql server joins?

556


What is single-user mode and what are the steps you should follow to start sql server in single-user mode?

552


What are sql server procedures?

541


What is use of attribute hierarchy ordered ? : sql server analysis services, ssas

557


what's sql server? : Sql server database administration

494


Can we call stored procedure in view in sql server?

495


what is the primary use of the model database? : Sql server administration

502