SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard dethfire's Avatar
    Join Date
    Aug 2000
    Posts
    2,477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Counting records

    say I have two fields claimid and itemnumber, it looks like this:

    CLAIMID ITEMNUMBER
    1000 1
    1000 2
    1000 3
    1000 4


    How do I find the last itemnumber field value that keeps within the same claimid? For instance, what if the item number went up to 5 or 6.
    Free Science Homework Help
    http://www.physicsforums.com

  2. #2
    SitePoint Wizard Goof's Avatar
    Join Date
    Feb 2001
    Location
    Pittsburgh, PA
    Posts
    1,154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know this works for SQL Server (which database are you running?):
    Code:
    SELECT TOP 1 ITEMNUMBER WHERE CLAIMID=1000 ORDER BY ITEMNUMBER DESC
    Hope that helps,
    Goof
    Nathan Rutman
    A slightly offbeat creative.

  3. #3
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT * FROM aTableName WHERE CLAIMID=1000 ORDER BY ITEMNUMBER DESC LIMIT 1

  4. #4
    SitePoint Wizard Goof's Avatar
    Join Date
    Feb 2001
    Location
    Pittsburgh, PA
    Posts
    1,154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    err...yeah, that will probably work better since I forgot my FROM clause .

    Goof
    Nathan Rutman
    A slightly offbeat creative.


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
  •