Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Syntax Select Top in each group

Posted on 2015-01-22
2
Medium Priority
?
247 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 2000 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

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

609 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