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 are the differences between triggers and stored procedures?
Explain data warehousing in sql server?
A trigger can reference objects outside the current database? State true or false.
What does COMMIT command do?
How do we Backup SQL Azure Data?
How to change parameter value inside the report?
Where views are stored in sql server?
How we can refresh the view?
How to optimize stored procedures in sql server?
After removing a table from database, what other related objects have to be dropped explicitly?
List the different normalization forms?
Which operator do you use to return all of the rows from one query except rows are returned in a second query?
What is a print index?
Can we use where clause with group by?
What is serializable?