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


Please Help Members By Posting Answers For Below Questions

Why use “pivot” in sql server?

621


Differentiate between sql temp table vs table variable?

513


How to change server name in sql server?

562


How do I find query history in sql server?

514


What will be the maximum number of index per table?

587






Mention the different types of replication in sql server.

561


What is difference between oltp and olap?

572


Describe the left outer join & right outer join. : sql server database administration

582


What is the sql server agent?

580


What is mean by dml?

535


What do you think of this implementation? Can this be implemented better?

531


what is an extended stored procedure? : Sql server database administration

494


What is Cross Join and in which scenario do we use Cross Join?

568


Explain what is lock escalation?

573


How do you clear a log file?

507