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 / lince p. thomas
select T.empname,salary from
(
select a.empname as empname ,a.salary as salary from dep1 a
union all
select b.empname as empname,b.salary as salary from dept2 b
)T where T.salary=(select max(T.salary) as salary from
(select max(a.salary) as salary,a.empname as empname
from dep1 a group by a.empname
union all
select max(b.salary)as salary,b.empname as empname from
dept2 b group by b.empname)T
)
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How can you tell if a database object is invalid?
Call by value and call by reference in procedure and function, with NOCOPY.
What is the difference between a stored procedure and a user defined function?
What do we need queues in sql service broker?
How to execute function in stored procedure sql server?
What do you understand by the denormalisation?
Can I disable or restrict ssrs export formats (rendering formats)?
What will happen if a column containing char type data is changed to the nchar data type?
What are the different types of normalization?
what kind of lan types do you know? : Sql server database administration
In how many ways you can invoke ssrs reports?
What is the difference between mysql and sql server?
How do I save a stored procedure in sql server?
Can you explain various data region available in ssrs with their use?
What is difference between Datepart() and Datename() in SqlServer?