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

What is a bit datatype?

1021


Explain the types of indexes.

1296


How many types of database relationship in sql server?

1103


Give the query of getting last two records from the table in SQL SERVER?

1010


What is a result set object returned by odbc_exec()?

1078


Do you know what are the restrictions applicable while creating views? : SQL Server Architecture

1052


How to create prepared statements using odbc_prepare()?

1104


How to insert a new row into a table with "insert into" statements in ms sql server?

1016


How to create a trigger for insert only?

1085


How optimize sql query with multiple joins in sql server?

955


What is isolation levels?

1082


Explain Reporting Life Cycle?

132


What are the restrictions applicable while creating views? : SQL Server Architecture

1086


How to throw custom exception in Stored Procedure?

1096


You want to implement the one-to-many relationship while designing tables. How would you do it?

996