C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Find highest salary among two tables


Posted Date: 26 Apr 2008    Resource Type: Code Snippets    Category: SQL

Posted By: @@@ Hyderabadi Biryani @@@       Member Level: Diamond
Rating:     Points: 2



The following sample sql query illustrates how to find the top salary between two tables.



SELECT TOP 1 sal
FROM (
SELECT MAX(sal) AS sal FROM sal1
UNION
SELECT MAX(sal) AS sal FROM sal2
) a ORDER BY sal DESC



The 2 tables in the above example are sal1 and sal2. This query can be extended to more than two tables also, just by having more UNIONs. "TOP 1 sal" construct helps pick the first entry in "sal" column.




Responses

Author: akhilesh chauhan    29 Apr 2008Member Level: Gold   Points : 2
SELECT Max(sal)
FROM (
SELECT MAX(sal) AS sal FROM sal1
UNION
SELECT MAX(sal) AS sal FROM sal2
) a


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Find the highest salary among two tables  .  Find the highest salary among several tables  .  Find the highest salary  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Delete Duplicate Records
Previous Resource: find nth highest salary
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

conference call

Contact Us    Privacy Policy    Terms Of Use