Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2015
    Posts
    1

    Unanswered: I have a problem with JOIN for 3 tables - Select last recod

    This is the Databases (for example)
    Click image for larger version. 

Name:	i4cXG.png 
Views:	6 
Size:	11.8 KB 
ID:	16574

    I have this code

    Code:

    Code:
    FROM vouchers AS A
    LEFT JOIN cod_return B ON A.voucher = B.voucher_id
    LEFT JOIN STATUS C ON A.voucher = C.voucher_id
    WHERE B.voucher_id IS NULL
    AND B.date IS NULL
    AND A.name IS NOT NULL
    AND C.status = "delivered"
    LIMIT 0 , 30
    So, I get data from 3 tables, only if the C.status = "delivered". I want to get the last data of that voucher on table "status", doesn't matter if it is "delivered".

    This is what I want as result
    Click image for larger version. 

Name:	d3QCA.png 
Views:	4 
Size:	4.6 KB 
ID:	16573

    Any thoughts?

  2. #2
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    in that case you would have to remove
    AND C.status = "delivered"
    and replace it with the predicate that would get you that most recent record. Do you have a sequence number associated, a timestamp that you could then say equals the MAX for your delivery.
    Dave

Posting Permissions

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