Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2004
    Location
    Brazil
    Posts
    6

    Unanswered: Problems with sub-query

    Hi there folks, im new at PostgreSQL and i am having a noob problem creating a query, if someone can help i will be greatfull, tnks ...


    I have 2 tables, just as example:

    Customer
    customer_id
    name
    ...

    Orders
    order_id
    customer_id
    order_date


    And i am trying to execute:


    select A.name, Z.order_date
    FROM Customer AS A ,
    (select X.*
    from ORDERS X LEFT JOIN Customer AS A ON (X.customer_id = A.customer_id)
    ORDER BY X.date DESC
    LIMIT 1
    ) AS Z


    I want only one registry from my subquery ... in SQLServer i use:

    select A.name,
    order_date = (select X.order_date
    from Orders X where X.customer_id = A.customer_id)
    from Customer A
    ...


    Someone can help me?
    tnkx. =)

  2. #2
    Join Date
    May 2008
    Posts
    277
    It's not very clear what you're trying to do. Select one order per customer? If so, a simple join should do the trick.
    Last edited by futurity; 11-02-11 at 12:01.

Posting Permissions

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