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

Why would you call update statistics?

567


can you implement data mining in SSRS?

113


What are the restrictions while creating batches in sql server?

569


can you instantiate a com object by using t-sql? : Sql server database administration

508


What is delete query?

505






How do we know if any query is retrieving a large amount of data or very little data?

544


Explain what is the difference between a local and a global temporary table?

503


What are three major types of constraints?

508


What is difference between temp table and cte?

523


1.what is the diff between nolock optimizer and read uncommitted isolation? 2.what is the diff between revoke and deny? 3.what is percieved down time? 4.whether password protection are required for backups?if yes why?if no why? 5.what is fill factor? 6.what is cost analysis? 7.what is mean by piece meal restore? 8.what is 'rowguidcol'? 9.impersonate permission? 10.what is selectivity?

1616


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

477


Tell me about normalization in DBMS.

570


When would you use an insert into .. Select option versus an insert into .. Values option? Give an example of each?

637


What are the different types of sub-queries?

587


How to drop existing views from a database in ms sql server?

518