On Tue, Sep 12, 2006 at 04:46:28PM +0100, Steven Murdoch wrote:
> Here is an example of a setup and what I could like to achieve. Does
> anyone have suggestions on what is the best way to get the desired
> result?

Use the aggregate over an ordered subquery:

SELECT name, trim(concat(code || ' ')) AS codes
FROM (
  SELECT a.name, b.code
  FROM a
  LEFT JOIN ab ON a.id = ab.a_id
  LEFT JOIN b ON ab.b_id = b.id
  ORDER BY b.code
) AS s
GROUP BY name
ORDER BY name;

Here's a comment from Tom Lane, one of the core developers, on
feeding the aggregate based on the subquery's order:

http://archives.postgresql.org/pgsql-general/2005-09/msg00047.php

-- 
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to [EMAIL PROTECTED] so that your
       message can get through to the mailing list cleanly

Reply via email to