Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TdmVT-0007tu-Li for pgsql-sql@arkaria.postgresql.org; Wed, 28 Nov 2012 18:37:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TdmVS-0002ba-Id for pgsql-sql@arkaria.postgresql.org; Wed, 28 Nov 2012 18:37:10 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TdmVR-0002bU-F0 for pgsql-sql@postgresql.org; Wed, 28 Nov 2012 18:37:09 +0000 Received: from mail-qc0-f174.google.com ([209.85.216.174]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TdmVP-0007k2-Lo for pgsql-sql@postgresql.org; Wed, 28 Nov 2012 18:37:08 +0000 Received: by mail-qc0-f174.google.com with SMTP id o22so9901602qcr.19 for ; Wed, 28 Nov 2012 10:37:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer :x-gm-message-state; bh=DLwJJKRy4hyM+W6OVJzg1p7xMqNstNWUgwAMfCSfUdQ=; b=Em0wyHIHM0U4856AhL0RAZV26SVo8NxIQORpxbt8wDnIRTPaPfXQWsnbt0P1D6MbtW iJdN4AjuytuWNNq0F12tGU7dz5fsl7Jpz5quIpyeWKAFsUU8//KUvVwQRrjcTbjf1ZP/ Dyman1xGP2xkpyQZcN9b0QODuNSUQP5xYX7f+pQl2ZckgaQ8eZUrk6EeMOZV+hBqJctD mrxlq+Yc8zkegkw/PDTA7MxZ+2Fj9IE24RwzurZvjXgBVbT9ASf74qwVAQ+Zb43nhSJX FhDmlVKIwfnuBYVb/JhoS36mnrffjBPpV/XudeY3l4Qafky/ilGdA8O6z2vZ5/UJshB8 fDQA== Received: by 10.49.95.73 with SMTP id di9mr24976335qeb.37.1354127826429; Wed, 28 Nov 2012 10:37:06 -0800 (PST) Received: from [192.168.1.111] (rrcs-208-105-82-84.nyc.biz.rr.com. [208.105.82.84]) by mx.google.com with ESMTPS id f7sm11498059qeg.12.2012.11.28.10.37.02 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 28 Nov 2012 10:37:05 -0800 (PST) Subject: Re: Joining several rows into only one Mime-Version: 1.0 (Apple Message framework v1280) Content-Type: text/plain; charset=iso-8859-1 From: "Jonathan S. Katz" In-Reply-To: Date: Wed, 28 Nov 2012 13:37:01 -0500 Cc: pgsql-sql@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <5F7A236E-DB07-4583-8492-2CAB3720FBA3@excoventures.com> References: To: JORGE MALDONADO X-Mailer: Apple Mail (2.1280) X-Gm-Message-State: ALoCoQmpyhRHrcVIvcLyo2wprasosccdn55Fpn/S/J1fcp/sb9KccaxDWJ8/JLRPuAKVaY/4ZB69 X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On Nov 28, 2012, at 1:33 PM, JORGE MALDONADO wrote: > I have a SELECT statement that gives me a result like this: >=20 > SONG ARTIST > ----------------------------------- > Song1 Artist1 > Song1 Artist2 > Song1 Artist3 > Song2 Artist2 > Song3 Artist4 > Song4 Artist1 > Song5 Artist4 >=20 > As you can see, the same song may belong to more than one artist, and thi= s is fine. What I would like to do is NOT to get several rows, one for each= different artist, but to join all of the artists in one column and display= only one row. > Is this possible? Hi Jorge, Try the array_agg function: SELECT song, array_agg(artist) FROM table GROUP BY song; Best, Jonathan --=20 Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql