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
What are translations and its use? : sql server analysis services, ssas
What do you understand by mirroring and mention the advantages of the mirroring?
What is advantage data architect?
Explain how dts is used to extract, transform and consolidate data?
How to create new tables with "select ... Into" statements in ms sql server?
Explain about protocol layer present in SQL server?
What is an example of a foreign key?
What is the main purpose of having conversation group?
What is self join in sql server joins?
What is single-user mode and what are the steps you should follow to start sql server in single-user mode?
What are sql server procedures?
What is use of attribute hierarchy ordered ? : sql server analysis services, ssas
what's sql server? : Sql server database administration
Can we call stored procedure in view in sql server?
what is the primary use of the model database? : Sql server administration