pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: wstrzalka <wstrzalka@gmail.com>
To: pgsql-sql@postgresql.org
Subject: ordered by join? ranked aggregate? how to?
Date: Mon, 14 Sep 2009 07:25:33 -0700 (PDT)
Message-ID: <d7867e26-d5de-4c48-bfac-d6f266b47ec6@l34g2000vba.googlegroups.com> (raw)

What I need is to join 2 tables

CREATE TABLE master(
    id INT4
);


CREATE TABLE slave (
    master_id INT4,
    rank INT4,
    value TEXT);


What I need is to make the query:

SELECT m.id, array_agg(s.value) AS my_problematic_array
FROM master AS m LEFT JOIN slave AS s ON (m.id = s.master_id)
GROUP BY m.id;

return the 'my_problematic_array' in order specified by slave.rank

As you probably can guest I don't have any idea know how to do it :/








view thread (5+ messages)  latest in thread

Message-ID: <d7867e26-d5de-4c48-bfac-d6f266b47ec6@l34g2000vba.googlegroups.com>
Permalink:  ../d7867e26-d5de-4c48-bfac-d6f266b47ec6@l34g2000vba.googlegroups.com/
Also on:    postgresql.org/message-id/d7867e26-d5de-4c48-bfac-d6f266b47ec6@l34g2000vba.googlegroups.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: wstrzalka@gmail.com
  Subject: Re: ordered by join? ranked aggregate? how to?
  In-Reply-To: <d7867e26-d5de-4c48-bfac-d6f266b47ec6@l34g2000vba.googlegroups.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox