?
Solved

SQL Syntax Select Top in each group

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

Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

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…
Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 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