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 is index fragmentation in ms sql server?
Are there issues when exporting SSRS reports into Microsoft Excel? When my users are trying to export a SSRS report into Microsoft Excel, one or two columns in the report appear to merge together. Why might this be?
How to receive returning result from a query?
Explain different forms of normalization?
Explain what is sql server english query?
What is a primary key?
How to insert data into an existing table?
in the physical file layout, where should the transaction log be stored in relation to the data file?
How can we use ConnectorJ JDBC Driver with MS SQL?
Describe and explain about SQL native client?
Explain error and transaction handling in sql server?
Explain nested stored procedure. Syntax and an example for create nested stored procedure?
Can a stored procedure call itself or recursive stored procedure? How many levels sp nesting is possible?
Does sql server 2016 have ssms?
What is the purpose of update statistics and scope_identity() function?