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
What is subquery in sql?
How can I create a report based on a query? : sql server management studio
Is foreign key unique?
Does group by sort data?
Where is localdb stored?
How many columns can exist together per table?
What command is used to create a database in the sql server and how?
What happens on checkpoint?
How can we delete Duplicate row in table?
What is instead of trigger sql server?
List some major differences between triggers and stored procedures?
What are the restrictions while creating batches in sql server?
how can u get last observation in an unknown dataset ?
What is the security model used in sql server 2005?
What is the order in which the sql query is executed?