Re: simple (?) join
От | David W Noon |
---|---|
Тема | Re: simple (?) join |
Дата | |
Msg-id | 20090928122716.61b99cfb@dwnoon.ntlworld.com обсуждение исходный текст |
Ответ на | Re: simple (?) join (Gary Stainburn <gary.stainburn@ringways.co.uk>) |
Список | pgsql-sql |
On Mon, 28 Sep 2009 12:02:20 +0100, Gary Stainburn wrote about Re: [SQL] simple (?) join: [snip] >For some reason the reply I sent on Friday didn't get through. >What I need is all of the order record and all of the latest log entry >returning as a join. Specifically I want for each order the most >recent log entry timestamp and it's associated user - i.e. who made >the the last log entry and when. In that case, try this: SELECT o.*, ol.ol_timestamp, ol.ol_user FROM orders AS o INNER JOIN orders_log AS ol ON ol.o_id = o.o_id WHERE ol.ol_timestamp = (SELECT MAX(ol_timestamp) FROM orders_log AS ol2 WHERE ol2.o_id = o.o_id); This will omit orders that have never been logged. You have not specified what you want done with them. -- Regards, Dave [RLU #314465] ======================================================================= david.w.noon@ntlworld.com (David W Noon) =======================================================================
В списке pgsql-sql по дате отправления: