DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2005
    Posts
    110

    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

  2. #2
    Join Date
    Mar 2005
    Posts
    110
    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

  3. #3
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    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

  1. find version & service packs
    By rperez in forum Database
    Replies: 5
    Last Post: 01-02-2009, 04:14 PM
  2. Access & SQL Server
    By David Jones in forum Database
    Replies: 0
    Last Post: 08-31-2001, 12:22 PM
  3. SQL Min Max HELP!
    By Ian Stone in forum VB Classic
    Replies: 11
    Last Post: 07-20-2001, 03:16 AM
  4. max user connections with sql server 2000
    By gunnar in forum Database
    Replies: 1
    Last Post: 11-01-2000, 04:56 PM
  5. Re: ODBC error
    By Devaraj in forum Enterprise
    Replies: 0
    Last Post: 05-11-2000, 12:48 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links