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
Is it possible to call a stored procedure within a stored procedure?
Scalability, Availability, Integration with internet, etc.)?
what is spatial nonclustered index
How we create SQL Server 2005 Reporting Services ? Give me Sample
What are the tables in sql?
can a database be shrunk to 0 bytes, if not, why? : Sql server administration
What are the main sources of data?
What is difference between count (*) and count column?
What is a not null constraint?
what are defaults? : Sql server database administration
What is the use of custom fields in report?
How to check status of stored procedure in sql server?
How to define the name and server for a new dsn?
What is the syntax for encrypting a column in SQL Server?
What is temporary stored procedure?