Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2004
    Location
    STL
    Posts
    45

    Unanswered: getting MAX value and displaying record

    Hi all,

    I basically want to display the single row that has the highest 'jobid' using a SP. I was playing with MAX(jobid) but getting errors about no group by, etc. Where do I begin with this?

    Code:
    SELECT     Purchord, JobNo, Descr, customer, jobid
    FROM         Jobs

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    SELECT Purchord, JobNo, Descr, customer, jobid
    FROM Jobs
    INNER JOIN (SELECT MAX(jobid) jobid FOMR Jobs) HighestID ON Jobs.jobid = HighestID.jobid

    -or-

    SELECT TOP 1 Purchord, JobNo, Descr, customer, jobid
    FROM Jobs
    order by jobid desc
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    select top 1 Purchord, JobNo, Descr, customer, jobid
    from Jobs
    order by jobid desc

    Edit: beaten!!
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Aug 2004
    Location
    STL
    Posts
    45
    Ohhhh........!!!! Thank you very much guys!

  5. #5
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    2 MINUTES 2 LATE, RUDY!

    BOO-YAH!

    Fastest fingers in the midwest...
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •