On Wed, Sep 23, 2009 at 6:33 PM, Jim wrote:
> On Sep 23, 5:43 am, AnthonyV wrote:
> > Hello,
> >
> > I have a table like :
> >
> >date|value
> > ---
> > 2009-09-19 | 1
> > 2009-09-20 | 2
> > 2009-09-21 | 6
> > 2009-09-22 | 9
> > 200
Hi folks.
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?
You mean
to list the complete orders table and for each of its records, the
corresponding record on the orders_log with the latest ol_timestamp?
SELECT *
FROM orders_log main
JOIN
(
SELECT orders.*, MAX(orders_log.ol_timestamp) as latest
FROM orders
NATURAL JOIN orders_log
GROUP BY orders.*
)
Hmm...no, it seems, it is not allowable to
use orders.* on a
GROUP BY clause.
Unless you've defined for the table something called an ordering operator.
If you didn't, you'll have to include all the fields from the orders table
in the GROUP BY clause
HTH
Best,
Oliveiros
- Original Messa
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 se
David W Noon wrote:
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,
On Thu, 24 Sep 2009 16:15:07 -0400, justin wrote about Re: [SQL] simple
(?) join:
>
>
>David W Noon wrote: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 p
On Thursday 24 Sep 2009, Gary Stainburn wrote:
> Hi folks.
>
> 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,
> );
>
> H