Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 / swati tripathi

SELECT
OUTERTABLE.EMPID,
MAX(OUTERTABLE.SALARY)

FROM

(SELECT EMPID,MAX(SALARY) AS SALARY
FROM DEP1
GROUP BY EMPID
UNION ALL
SELECT EMPID,MAX(SALARY) AS SALARY
FROM DEP2
GROUP BY EMPID) AS OUTERTABLE
GROUP BY OUTERTABLE.EMPID

Is This Answer Correct ?    8 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to download and install sql server 2005 books online?

1203


What is “asynchronous” communication in sql server service broker?

1044


What are the advantages of stored procedure in sql server?

898


Which is better statement or preparedstatement?

936


Can a table be created inside a trigger?

977


How does clustered and non clustered index work?

933


Do you know clustered and non-clustered index?

984


Why and when do stored procedure recompile?

990


How to filter out duplications in the returning rows in ms sql server?

1148


What is exporting and importing utility?

1096


Why should you use or avoid select * statements?

1034


What is cursor in ms sql server?

1157


What are the export options of ssrs?

174


Describe in brief sql server monitoring ways.

1058


How to locate and take substrings with charindex() and substring() functions?

1021