Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2003
    Location
    Planet World
    Posts
    2

    Unanswered: SQL Query (maybe nested)

    So, I have 2 tables CLIENTS and ORDERS.
    Can anybody advise an SQL query to get results below.
    Thanks in advance.
    ====================================
    Table CLIENTS:
    CLIENT_ID CLIENT_NAME CLIENT_PHONE
    ---------- ----------- ------------
    1 JOE (101)111 3333
    2 FRANK (101)444 6666
    3 ALBERT (101)222 0000
    ====================================
    Table ORDERS
    ORDER_ID ORDER_CLIENT ORDER_TIME ORDER_DELIVERED
    -------- ------------ ------------------ ---------------
    1 1 01/09/2003 10:00:00 NO
    2 1 02/09/2003 10:30:00 YES
    3 2 01/09/2003 20:00:00 NO
    4 2 03/09/2003 20:30:00 NO

    ====================================
    Output of The Query
    CLIENT_NAME CLIENT_PHONE THE_LAST_ORDER_TIME ORDER_DELIVERED
    ----------- ------------ ------------------- ---------------
    JOE (101)111 3333 02/09/2003 10:30:00 YES
    FRANK (101)444 6666 03/09/2003 20:30:00 NO
    ALBERT (101)222 0000 NULL NULL
    ====================================

  2. #2
    Join Date
    Feb 2003
    Location
    Auckland, NZ
    Posts
    150
    Try this

    Code:
    SELECT CLIENTS.CLIENT_NAME, CLIENTS.CLIENT_PHONE, ORDERS.ORDER_TIME, ORDERS.ORDER_DELIVERED
    FROM CLIENTS INNER JOIN ORDERS ON CLIENTS.CLIENT_ID =  ORDERS.ORDER_CLIENT
    JJ Kennedy
    Double J IT Solutions
    www.doublejit.co.nz

    VB 6, VB.NET, ASP.NET, MS SQL Server, MySQL, MS Access

  3. #3
    Join Date
    Sep 2003
    Location
    Planet World
    Posts
    2
    Originally posted by machado
    Try this

    Code:
    SELECT CLIENTS.CLIENT_NAME, CLIENTS.CLIENT_PHONE, ORDERS.ORDER_TIME, ORDERS.ORDER_DELIVERED
    FROM CLIENTS INNER JOIN ORDERS ON CLIENTS.CLIENT_ID =  ORDERS.ORDER_CLIENT
    ////////////////
    I would like to obtain the LAST order of the each client in the query.
    So, there should be a MAX(ORDERS.ORDER_TIME) or
    MAX(ORDER_ID) in the query.

Posting Permissions

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