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 / veeresh kethari

User CTE:

with Temp as(select max(sal) Sal from Table1
union
select max(sal) sal from Table2)
select top 1 * from Temp order by sal desc

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

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

603


How to create a view with data from multiple tables?

557


What new changes are being made in SQL Server?

574


What are the benefits of filtered indexes?

509


How to enter binary string literals in ms sql server?

583






What do you know about system database? : SQL Server Architecture

494


Does dbcc checkdb requires db to be in single_user mode? : sql server database administration

518


What is difference between count (*) and count column?

523


Why use identity in sql server?

561


what is the system function to get the current user's user id? : Sql server database administration

555


What number sorts of privileges are accessible in sql?

598


I applied Transactional with updatable subscriptions replication on 2 tables now i want to delete those 2 tables but i cannot delete those tables as replication is running how can i stop replication for those 2 tables(but i don't want to delete those replicated tables but i need to stop the replication) how can i do that

1438


How to skip remaining statements in a loop block using continue statements?

543


What is "scheduled jobs" or "scheduled tasks"?

554


What do you mean by a Composite primary key?

592