> I have two tables
>
> 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?

Maby this will work?

Get the unique o_id from the table orders and do a group by in a
subselect, and then select the other fields from the same table, ie:

select o_od, max(o_field1), max(o_field2) ... from orders where o_id
in (select o_id from orders group by o_id) group by o_id order by
o_id;

This off course assumes that o_id is a serial (and thus that timestamp
will always be higher etc.).

-- 
regards
Claus

When lenity and cruelty play for a kingdom,
the gentler gamester is the soonest winner.

Shakespeare

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

Reply via email to