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
What are the basic functions for master, msdb, model, tempdb and resource databases?
Explain what are various ways to enhance the ssrs report?
What is a cursor, index in sql?
What is the stuff?
How to enter unicode character string literals in ms sql server?
Can sql servers linked to other servers like oracle?
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?
Why use view instead of a table?
How many types of keys are there?
Why I am getting this error when dropping a database in ms sql server?
How to select some specific rows from a table in ms sql server?
What are the different types of stored procedures?
What is the dbcc command and why is it used?
What is use of @@ spid in sql server?
What does REVERT do in SQL Server 2005?