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
How to download and install sql server 2005 books online?
What is “asynchronous” communication in sql server service broker?
What are the advantages of stored procedure in sql server?
Which is better statement or preparedstatement?
Can a table be created inside a trigger?
How does clustered and non clustered index work?
Do you know clustered and non-clustered index?
Why and when do stored procedure recompile?
How to filter out duplications in the returning rows in ms sql server?
What is exporting and importing utility?
Why should you use or avoid select * statements?
What is cursor in ms sql server?
What are the export options of ssrs?
Describe in brief sql server monitoring ways.
How to locate and take substrings with charindex() and substring() functions?