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 / akhilesh
Try this. I have tried it.
Select id, name, Max(salary) as salary from
(Select id, name, salary from emp where salary = (Select
Max(salary) from emp)
Union
Select id, name, salary from emp1 where salary = (Select
Max(salary)from emp1)) as B
where salary = (
Select Max(salary) as salary from
(Select id, name, salary from emp where salary = (Select
Max(salary) from emp)
Union
Select id, name, salary from emp1 where salary = (Select
Max(salary)from emp1)) as C
)
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Why use “pivot” in sql server?
Differentiate between sql temp table vs table variable?
How to change server name in sql server?
How do I find query history in sql server?
What will be the maximum number of index per table?
Mention the different types of replication in sql server.
What is difference between oltp and olap?
Describe the left outer join & right outer join. : sql server database administration
What is the sql server agent?
What is mean by dml?
What do you think of this implementation? Can this be implemented better?
what is an extended stored procedure? : Sql server database administration
What is Cross Join and in which scenario do we use Cross Join?
Explain what is lock escalation?
How do you clear a log file?