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 a bit datatype?
Explain the types of indexes.
How many types of database relationship in sql server?
Give the query of getting last two records from the table in SQL SERVER?
What is a result set object returned by odbc_exec()?
Do you know what are the restrictions applicable while creating views? : SQL Server Architecture
How to create prepared statements using odbc_prepare()?
How to insert a new row into a table with "insert into" statements in ms sql server?
How to create a trigger for insert only?
How optimize sql query with multiple joins in sql server?
What is isolation levels?
Explain Reporting Life Cycle?
What are the restrictions applicable while creating views? : SQL Server Architecture
How to throw custom exception in Stored Procedure?
You want to implement the one-to-many relationship while designing tables. How would you do it?