Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 26th, 2005, 05:44 AM
Milorad Milorad is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 1 Milorad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 14 sec
Reputation Power: 0
select max values

Hello. I need some help with an sql statement. Maybe one can help.

I got this table:

employee,value,zone
11,1541,0
11,1300,0
11,1810,1
11,1710,1
11,2000,2
11,1900,2

applying this statement:
select max(value),employee,zone
from table
group by employee,zone;

... delivers this result:
max(value),employee,zone
1541,11,0
1810,11,1
2000,11,2

All I want to get is one single line per employee, since I'm only interested in that row which has the largest values among the employees' data.

I expect this result:
11,2000,2

Can anyone help me out with the statement?



Many thanks
Milorad

Reply With Quote
  #2  
Old July 26th, 2005, 06:19 AM
swampBoogie swampBoogie is online now
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,775 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 16 h 2 m 7 sec
Reputation Power: 37
Code:
select value,employee,zone
from t as q
where value = (select max(value)
 from t
 where t.employee = q.employee)

Reply With Quote
  #3  
Old July 26th, 2005, 09:10 AM
SilverDB's Avatar
SilverDB SilverDB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Romania
Posts: 173 SilverDB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 45 m 53 sec
Reputation Power: 4
Send a message via Yahoo to SilverDB
You will get the same result if you run this query:
Code:
SELECT FIRST 1 VALUE,EMPLOYEE,ZONE
FROM TABLE
ORDER BY VALUE DESC
__________________
If i've been helpful, please add to my reputation.
My unfinished site: http://www.dever.ro

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > select max values


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway