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

What are the basic functions for master, msdb, model, tempdb and resource databases?

553


Explain what are various ways to enhance the ssrs report?

568


What is a cursor, index in sql?

575


What is the stuff?

527


How to enter unicode character string literals in ms sql server?

574






Can sql servers linked to other servers like oracle?

542


how would you write a sql query to compute a frequency table of a certain attribute involving two joins? What changes would you need to make if you want to order by or group by some attribute? What would you do to account for nulls?

1100


Why use view instead of a table?

516


How many types of keys are there?

526


Why I am getting this error when dropping a database in ms sql server?

588


How to select some specific rows from a table in ms sql server?

569


What are the different types of stored procedures?

554


What is the dbcc command and why is it used?

571


What is use of @@ spid in sql server?

679


What does REVERT do in SQL Server 2005?

558