| From: | David W Noon <dwnoon(at)ntlworld(dot)com> |
|---|---|
| To: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: simple (?) join |
| Date: | 2009-09-24 18:46:29 |
| Message-ID: | 20090924194629.44bc236f@dwnoon.ntlworld.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
On Thu, 24 Sep 2009 16:16:36 +0100, Gary Stainburn wrote about [SQL]
simple (?) join:
>create table orders (
>o_id serial primary key
>...
>);
>
>create table orders_log (
>ol_id serial primary key,
>o_id int4 not null references orders(o_id),
>ol_timestamp timestamp,
>ol_user,
>);
>
>How can I select all from orders and the last (latest) entry from the
>orders_log?
SELECT * FROM orders
WHERE o_id IN (SELECT o_id FROM orders_log
WHERE ol_timestamp = (SELECT MAX(ol_timestamp) FROM orders_log));
No joins required.
--
Regards,
Dave [RLU #314465]
=======================================================================
david(dot)w(dot)noon(at)ntlworld(dot)com (David W Noon)
=======================================================================
| From | Date | Subject | |
|---|---|---|---|
| Next Message | justin | 2009-09-24 20:15:07 | Re: simple (?) join |
| Previous Message | Oliveiros C, | 2009-09-24 17:26:35 | Re: simple (?) join |