Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2007
    Location
    Manila, Philippines
    Posts
    132

    Unanswered: get latest entry

    hi,
    can anyone please help me how to get thy latest entry in my table
    my query is
    Code:
    SELECT
    a.transid,
    a.artid,
    b.remarks,
    b.errID
    
    FROM tbl_transactions as a
    inner join tbl_errordetail as b on (b.transid = a.transid)
    
    where a.artid = 123
    i want to get the latest entry for b.errID without grouping by

    thanks in advance
    Take Nothing But Pictures;
    Leave Nothing But Footprints;
    Kill Nothing But Time;

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    order by mycolumn DESC
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Oct 2007
    Location
    Manila, Philippines
    Posts
    132
    i only need the record that has the highest value
    Take Nothing But Pictures;
    Leave Nothing But Footprints;
    Kill Nothing But Time;

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Limit 1 ?
    George
    Home | Blog

  5. #5
    Join Date
    Feb 2008
    Location
    Bandung - Indonesia
    Posts
    15
    SELECT ...
    ORDER BY b.errID DESC LIMIT 1
    Forum Informatika - Indonesian Informatics Online Community - http://if.web.id

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT a.transid
         , a.artid
         , b.remarks
         , b.errID
      FROM tbl_transactions AS a
    INNER 
      JOIN tbl_errordetail AS b 
        ON b.transid = a.transid
       AND b.errID =
           ( SELECT MAX(errID)
               FROM tbl_errordetail 
              WHERE transid = a.transid )
     WHERE a.artid = 123
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Jan 2009
    Posts
    1
    You need to have an AutoID column that increaments automatically every time you add a new record.To select the most recent record,just write you SQl statement like this:

    Select * from tablename order by AutoID desc
    This will display the most recent records first
    Hope this helps
    AMY

  8. #8
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    mayz, you did not understand the question

    and in any case getting the latest does not "require" an auto_increment
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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