Solved

SQL Syntax Select Top in each group

Posted on 2015-01-22
2
209 Views
Last Modified: 2015-01-22
Hello Experts,

I have a table called header that contains 2 columns SNUM and Time. I am trying to select the highest value of time per group. See attached image.

Expected result is:
SNUM         Time
1                 1/22/15 1:45AM
2                 1/22/15 3:25AM
3                 1/22/15 2:05AM


SyBase SQL Anywhere v10
table.png
0
Comment
Question by:triphen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Accepted Solution

by:
Mike Eghtebas earned 500 total points
ID: 40565743
Select Distinct SNUM, (Select Top 1 t2.Time From Table1 t1 Order By t2.Time Dedc) As MaxTime From Table1 t1

or

Select SNUM, Max(Time) As MaxTime From Table1 Group By  SNUM Order By Time Desc

or just

Select SNUM, Max(Time) As MaxTime From Table1 Group By  SNUM
0
 

Author Closing Comment

by:triphen
ID: 40565757
The second one worked !!!!! Thanks!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question