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 / praveend

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 ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is subquery in sql?

561


How can I create a report based on a query? : sql server management studio

552


Is foreign key unique?

567


Does group by sort data?

507


Where is localdb stored?

547






How many columns can exist together per table?

699


What command is used to create a database in the sql server and how?

594


What happens on checkpoint?

606


How can we delete Duplicate row in table?

624


What is instead of trigger sql server?

491


List some major differences between triggers and stored procedures?

514


What are the restrictions while creating batches in sql server?

575


how can u get last observation in an unknown dataset ?

1985


What is the security model used in sql server 2005?

500


What is the order in which the sql query is executed?

514