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 is index fragmentation in ms sql server?

606


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?

134


How to receive returning result from a query?

586


Explain different forms of normalization?

534


Explain what is sql server english query?

533






What is a primary key?

544


How to insert data into an existing table?

571


in the physical file layout, where should the transaction log be stored in relation to the data file?

538


How can we use ConnectorJ JDBC Driver with MS SQL?

568


Describe and explain about SQL native client?

622


Explain error and transaction handling in sql server?

506


Explain nested stored procedure. Syntax and an example for create nested stored procedure?

535


Can a stored procedure call itself or recursive stored procedure? How many levels sp nesting is possible?

528


Does sql server 2016 have ssms?

519


What is the purpose of update statistics and scope_identity() function?

602