If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > Problems with sub-query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-26-11, 12:55
BE_QUICK BE_QUICK is offline
Registered User
 
Join Date: Jul 2004
Location: Brazil
Posts: 6
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. =)
Reply With Quote
  #2 (permalink)  
Old 11-01-11, 11:37
futurity futurity is offline
Registered User
 
Join Date: May 2008
Posts: 270
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 11:01.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On