Order of JOIN results
join, postgresql
Solution
Finally i did it this way...
SELECT
orden.id,
array_to_string(array_agg(observaciones.fecha_hora),'<br>') as observaciones
FROM orden
LEFT JOIN (
SELECT orden_id, fecha_hora FROM observacion ORDER BY fecha_hora DESC
) as observaciones ON observaciones.orden_id = orden.id
GROUP BY orden.id
Thanks to all..
Problem
I have this query ``` SELECT orden.id, array_to_string(array_agg(observaciones.fecha_hora),'<br>') as observaciones FROM orden LEFT JOIN observacion observaciones ON observaciones.orden_id = orden.id GROUP BY orden.id ``` and it's returning this: ``` orden.id = 5878 observaciones 2012-03-15 01:39:11 2012-03-15 01:40:28 2012-03-15 01:40:42 2012-03-15 09:09:08 2012-03-15 09:11:10 2012-03-15 01:18:34 2012-03-15 01:19:27 2012-03-15 09:17:01 2012-03-15 09:17:36 2012-03-15 03:16:58 2012-03-15 01:21:01 2012-03-15 03:17:06 2012-03-15 03:17:26 2012-03-15 01:27:33 2012-03-15 03:18:05 2012-03-15 03:24:56 2012-03-15 03:49:24 2012-03-15 01:27:43 2012-03-15 01:38:30 2012-03-15 06:30:13 ``` and the question is, how can I obtain those date time in order DESC I can't do a subquery because I'm optimizing a old query, I really need a JOIN. I'm using postgresql.