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
Differentiate between mongodb vs. Sql server?
Explain what are the events recorded in a transaction log?
Explain intellisense for query editing
What is buffer cash in sql server?
What is a dbms wizard?
What is index, cluster index and nonclustered index?
What are the differences between local and global temporary tables?
Explain what are the basic functions for master, msdb, model, tempdb databases?
Explain different types of index?
What are the advantages of using stored procedures?
What are the different types of locks in the database?
How to list all user names in a database?
Explain identity in sql server?
What is checkpoint in sql server?
How to find Duplicate Records In table?