-
how to get max in sql
Hello,
I have a table, like this
ID, SendData, Sequence
0025 NULL 3
0019 2005-12-02 00:00:00.000 1
0025 2005-12-02 00:00:00.000 1
0036 2005-12-05 00:00:00.000 1
I want to get the result, like this, get max(sequence) of ID
0025 NULL 3
0019 2005-12-02 00:00:00.000 1
0036 2005-12-05 00:00:00.000 1
How to write this sql using one statement
thanks
-
I got a result, but it miss a row.
select id,senddate,sequence from myTable As A WHERE A.sequence = (SELECT MAX(B.sequence) from Mytable as B where B.id = A.id)
the Result is:
0025 NULL 3
0019 2005-12-02 00:00:00.000 1
the last missed
0036 2005-12-05 00:00:00.000 1
Please tell me what is wrong. thanks
-
What kind of database? If you're using MS Access, you can do this:
SELECT ID, FIRST(SendDate), MAX(Sequence)
FROM myTable
GROUP BY ID
SQL Server, unfortunately, does not have a FIRST function, so I don't know if you can do this with a single SELECT in SQL Server.
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
Similar Threads
-
By rperez in forum Database
Replies: 5
Last Post: 01-02-2009, 04:14 PM
-
By David Jones in forum Database
Replies: 0
Last Post: 08-31-2001, 12:22 PM
-
By Ian Stone in forum VB Classic
Replies: 11
Last Post: 07-20-2001, 03:16 AM
-
By gunnar in forum Database
Replies: 1
Last Post: 11-01-2000, 04:56 PM
-
By Devaraj in forum Enterprise
Replies: 0
Last Post: 05-11-2000, 12:48 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks