Re: simple (?) join

Поиск
Список
Период
Сортировка
От justin
Тема Re: simple (?) join
Дата
Msg-id 4ABE6360.20205@emproshunts.com
обсуждение исходный текст
Ответ на Re: simple (?) join  (David W Noon <dwnoon@ntlworld.com>)
Ответы Re: simple (?) join  (David W Noon <dwnoon@ntlworld.com>)
Список pgsql-sql
<br /><br /> David W Noon wrote: <blockquote cite="mid:20090924222106.23a5c1f3@dwnoon.ntlworld.com"
type="cite"><blockquotetype="cite"><pre wrap="">A nested query
 

Select  orders.*,  (SELECT MAX(ol_timestamp) FROM orders_log where orders_log.o_id =
orders.oid)   </pre></blockquote><pre wrap="">>From orders

That won't give the desired results. I don't think the SQL parser will
even accept it. </pre></blockquote> Yes this is a  valid SQL statement use similar ones a great deal.  The problem with
nestedqueries is they can only return 1 record per match.  Another problem can be performance it has to run for every
recordin order tables and it occurs pre filter conditions <br /><blockquote
cite="mid:20090924222106.23a5c1f3@dwnoon.ntlworld.com"type="cite"><pre wrap=""> </pre><blockquote type="cite"><pre
wrap="">Stillanother option is using a join
 

Select  orders.*, ol_timestamp  From orders  left join (SELECT MAX(ol_timestamp), o_id FROM orders_log group by
o_id) as JoinQuery on JoinQuery.o_id = orders.o_id   </pre></blockquote><pre wrap="">
That won't give the desired results either. If you change "left" to
"inner" you will be closer though.

Both of your queries will retrieve the entire orders table with a
timestamp of some sort from the orders_log table. </pre></blockquote><br /> I read the question as Gary wanted the
entireorders table with the greatest timestamp from the logs table....<br /><br /> Quoting Gary<br /><pre wrap="">"How
canI select <u><big><big><b>all from orders</b></big></big></u> and the <b><u>last (latest)</u></b> entry from the 
 
orders_log?"</pre><br /><br /><br /><br />

В списке pgsql-sql по дате отправления:

Предыдущее
От: justin
Дата:
Сообщение: Re: simple (?) join
Следующее
От: David W Noon
Дата:
Сообщение: Re: simple (?) join