David W Noon wrote: Yes this is a valid SQL statement use similar ones a great deal. The problem with nested queries is they can only return 1 record per match. Another problem can be performance it has to run for every record in order tables and it occurs pre filter conditionsA nested query Select orders.*, (SELECT MAX(ol_timestamp) FROM orders_log where orders_log.o_id = orders.oid)>From ordersThat won't give the desired results. I don't think the SQL parser will even accept it. Still another 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_idThat 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. I read the question as Gary wanted the entire orders table with the greatest timestamp from the logs table.... Quoting Gary "How can I select all from orders and the last (latest) entry from the orders_log?" |
- [SQL] simple (?) join Gary Stainburn
- Re: [SQL] simple (?) join Oliveiros C,
- Re: [SQL] simple (?) join Oliveiros C,
- Re: [SQL] simple (?) join David W Noon
- Re: [SQL] simple (?) join justin
- Re: [SQL] simple (?) join David W Noon
- Re: [SQL] simple (?) join justin
- Re: [SQL] simple (?) join David W Noon
- Re: [SQL] simple (?) join justin
- Re: [SQL] simple (?) join Gary Stainburn
- Re: [SQL] simple (?) join Oliveiros C,
- Re: [SQL] simple (?) join David W Noon
- Re: [SQL] simple (?) join Gary Stainburn
- Re: [SQL] simple (?) join Oliveiros C,
- Re: [SQL] simple (?) join justin
- Re: [SQL] simple (?) join Raj Mathur
- Re: [SQL] simple (?) join Claus Guttesen