Solved

SQL Syntax Select Top in each group

Posted on 2015-01-22
2
170 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
2 Comments
 
LVL 33

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now