Re: [GENERAL] Subqueries - performance and use question

2007-02-01 Thread Demel, Jeff
I just wanted to say thanks to everyone for your help. -Jeff This email is intended only for the individual or entity to which it is addressed. This email may contain information that is privileged, confidential or otherwise protected from disclosure. Dissemination, distribution or copying of

Re: [GENERAL] Subqueries - performance and use question

2007-02-01 Thread Tom Lane
"Demel, Jeff" <[EMAIL PROTECTED]> writes: > Here's what I came up with: > SELECT customers.id, customers.firstname, > customers.lastname, customers.phone number, > (SELECT ar.billdate FROM ar > WHERE customers.customerid = ar.customerid > ORDER BY ar.billdate LIMIT 1) > AS l

Re: [GENERAL] Subqueries - performance and use question

2007-02-01 Thread Demel, Jeff
, 2007 11:09 AM To: Demel, Jeff; pgsql-general@postgresql.org Subject: RE: [GENERAL] Subqueries - performance and use question sorry, missing GROUP BY and some column naming was messed up but hopefully you get the idea: SELECT c.id, c.firstname, c.lastname, a.latest_billdate FROM customers c

Re: [GENERAL] Subqueries - performance and use question

2007-02-01 Thread George Pavlov
ql-general@postgresql.org > Subject: Re: [GENERAL] Subqueries - performance and use question > > try this approach: > > SELECT > c.id, > c.firstname, > c.lastname, > a.latest_billdate > FROM > customers c > INNER JOIN -- or LEFT if you want the NU

Re: [GENERAL] Subqueries - performance and use question

2007-02-01 Thread George Pavlov
try this approach: SELECT c.id, c.firstname, c.lastname, a.latest_billdate FROM customers c INNER JOIN -- or LEFT if you want the NULLs ( SELECT customer_id, max(billdate) as latest_billdate FROM ar ) a ON c.customerid = a.customerid WHERE c.status = 'new';