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 the use of for clause?
What is difference between view and materialized view?
What are the instances when triggers are appropriate?
How to receive output values from stored procedures?
Explain where clause?
What is the difference between upgrade and migration in sql server?
How to sort query output in descending order in ms sql server?
What is the significance of null value and why should we avoid permitting null values?
How do I create a trace in sql server?
Explain different types of Normalization.
What happens when the SQL Azure database reaches Max Size?
What is standby servers? Explain types of standby servers.
How do I setup a local sql server database?
What are magic tables in sql server?
How to grant a permission in ms sql server using "grant execute" statements?