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

Describe and explain about SQL native client?

622


Stored Procedure returns data from multiple tables. How to access it in your ASP.Net code?

557


What is the sql case statement used for? Explain with an example?

544


hi, how to link a text file and a .rpt file in my tables of sql server and to retrieve those records for further use. reply me as soon as possible.

1568


What is attribute? : sql server analysis services, ssas

593






What does it mean if @@cursor_row returns a negative number?

579


How to backup encryption key ?

127


What do you mean by a dependent functionality in a build?

664


What is the difference between varchar and nvarchar datatypes?

574


How to generate create procedure script on an existing stored procedure?

518


Tell me what is difference between clustered and non clustered index?

560


Tell me in brief how sql server enhances scalability of the database system?

540


Explain what are the different index configurations a table can have?

699


How to assign new column names in a view?

509


How would you use user_constraints table in DB?

596