Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id B7EB71337BA3 for ; Thu, 5 May 2011 22:06:23 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 61483-03 for ; Fri, 6 May 2011 01:06:17 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from nm22.bullet.mail.bf1.yahoo.com (nm22.bullet.mail.bf1.yahoo.com [98.139.212.181]) by mail.postgresql.org (Postfix) with SMTP id A6BFE1337B97 for ; Thu, 5 May 2011 22:06:15 -0300 (ADT) Received: from [98.139.212.149] by nm22.bullet.mail.bf1.yahoo.com with NNFMP; 06 May 2011 01:06:14 -0000 Received: from [98.139.212.194] by tm6.bullet.mail.bf1.yahoo.com with NNFMP; 06 May 2011 01:06:14 -0000 Received: from [127.0.0.1] by omp1003.mail.bf1.yahoo.com with NNFMP; 06 May 2011 01:06:14 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 666504.83138.bm@omp1003.mail.bf1.yahoo.com Received: (qmail 47930 invoked by uid 60001); 6 May 2011 01:06:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1304643974; bh=UnCYq43caVL3IhRln/YlnIRqIMffyHcUFBSumfDfYLk=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=S359FbtLbQdQV62Oq/cTIS6N2L0UAp1O54idNUEcdDrbUb6ylDBAVlcuSvC9iiyfSujUBKbaIlmqNi5dpY3Rfwhdqj1a+FAmhJ/dOYiudsJEJKPfP1Y32itSgHKrxKlKZW872hELrM8PySttLVUiHiPbpQUXPOaIRxxs9gxujYw= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=NM/qzVZaoczY5lF+iz9Gtd9ZP3CB4Z+4D1I1txlF670+bAjaUKWlvjfXifadYAcUnNvPsx3LQmse1hAIE8XL0r5TxmEMWr/ds83neeDV4+m2JKODTFWwhMx/OWnzUNeEvVG1xl/IBLV5H6zoiVrVU6oe7Guc2uFSivzeDf3RHJE=; Message-ID: <597398.41914.qm@web161309.mail.bf1.yahoo.com> X-YMail-OSG: zzOqwpUVM1lS9U5.kut7pClE3iORMkjSShKOjwEpVRZoJaB CHUvraGUNDla_zVWjtbGpoCyV2l.ASqdJIy.XhgPdxCcq91q5ptjrG2.Y9FT 7o0VDSRobCqcXNgbR6ZlQvc_YceVwHeu2Yv1J7AftSRNb7nyexYYT86EYV2S rOtnYt8mzaGOnVwJQWSAezppfs0ff5GdDh0Hto8.9.fj3V2pPIk556S16x0_ 6Pj7zfSV2hZr5k_Rpr..sowPA1nLh455JrObFwZ_4j05GMdboE4aGAzqHefD TyITgrZvpiF19cVIK2biZNqqzxecGGzNmzylP4.CaOj41_E5giBHBOKIK51S _DuqT2itKXjNDBm_l3HQTIJ_3RD9u2zDfBAar2IB3MxbwvWjawGmVUgs_VFH aUrytK0Yro.GMdnsSYcv2eOKnZGq7wVDoPUl_LyW.AG.vm.JGsVcjm6HrIQo t1lAcjDiUedylRIm3sgrkfx1F1W9yfRyHESJrS1ifwrkHaZqG61i747vm Received: from [135.11.3.4] by web161309.mail.bf1.yahoo.com via HTTP; Thu, 05 May 2011 18:06:14 PDT X-Mailer: YahooMailClassic/12.0.2 YahooMailWebService/0.8.110.299900 Date: Thu, 5 May 2011 18:06:14 -0700 (PDT) From: Claudio Adriano Guarracino Subject: Re: Select and merge rows? To: pgsql-sql@postgresql.org, "scorpdaddy@hotmail.com" In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1319849445-1304643974=:41914" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.422 tagged_above=-5 required=5 tests=BAYES_05=-0.5, FREEMAIL_FROM=0.001, FREEMAIL_REPLY=1.929, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RFC_ABUSE_POST=0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: * X-Archive-Number: 201105/31 X-Sequence-Number: 35315 --0-1319849445-1304643974=:41914 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Thank you very much! Your example help me a lot! The original query is more complex, but I can continue with this example. Thanks again! --- On Thu, 5/5/11, scorpdaddy@hotmail.com wrote: From: scorpdaddy@hotmail.com Subject: Re: [SQL] Select and merge rows? To: "Claudio Adriano Guarracino" , pgsql-sql@postgresql.= org Date: Thursday, May 5, 2011, 5:41 PM While there is insufficient information provided (a couple of table snippet= s), you may consider and experiment with the snippet below to get you start= ed. SELECT=20 =A0ids.id, =A0f1.value AS value1, =A0f2.value AS value2, =A0f3.value AS value3 FROM ( SELECT DISTINCT id FROM foo ) AS ids=20 LEFT JOIN foo f1=20 ON f1.id =3D ids.id=20 AND f1.order =3D 1 LEFT JOIN foo f2 ON f2.id =3D ids.id=20 AND f2.order =3D 2=20 LEFT JOIN foo f3=20 ON f3.id =3D ids.id=20 AND f3.order =3D 3 ORDER BY ids.id;=20 ----- Reply message ----- From: "Claudio Adriano Guarracino" Date: Thu, May 5, 2011 5:18 pm Subject: [SQL] Select and merge rows? To: Hello! I have a doubt about a query that I tried to do, but I cant...... This is the scenario: I have a table, with this rows: order=A0=A0=A0 ID=A0=A0=A0 value=A0=A0=A0=20 ---------------------- 1=A0=A0=A0 1000=A0=A0=A0 3 2=A0=A0=A0 1000=A0=A0=A0 5 3=A0=A0=A0 1000=A0=A0=A0 6 1=A0=A0=A0 1001=A0=A0=A0 1 2=A0=A0=A0 1001=A0=A0=A0 2 1=A0=A0=A0 1002=A0=A0=A0 4 2=A0=A0=A0 1002=A0=A0=A0 4 I need to get this table, divided by ID, like this: id=A0=A0=A0 value1=A0=A0=A0 value2=A0=A0=A0 value3 -------------------------------- 1000=A0=A0=A0 3=A0=A0=A0 5=A0=A0=A0 6 1001=A0=A0=A0 1=A0=A0=A0 2 1002=A0=A0=A0 1=A0=A0=A0 2 How I can do this? I tried with cursors and view, but i can't.... Any help is welcome! Thanks in advance! Regards, --0-1319849445-1304643974=:41914 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Thank you very much!
Your example help me = a lot!
The original query is more complex, but I can continue with this = example.
Thanks again!

--- On Thu, 5/5/11, scorpdaddy@hotmail.= com <scorpdaddy@hotmail.com> wrote:

From: scorpdaddy@hotmail.com <scorpdaddy@hotmail.com>
= Subject: Re: [SQL] Select and merge rows?
To: "Claudio Adriano Guarracin= o" <elninon@yahoo.com>, pgsql-sql@postgresql.org
Date: Thursday, M= ay 5, 2011, 5:41 PM

While there is insuffic= ient information provided (a couple of table snippets), you may consider an= d experiment with the snippet below to get you started.


SELECT <= br>  ids.id,
 f1.value AS value1,
 f2.value AS value= 2,
 f3.value AS value3
FROM
( SELECT DISTINCT id FROM foo ) AS ids=
LEFT JOIN foo f1
ON f1.id =3D ids.id
AND f1.order =3D 1
LEF= T JOIN foo f2
ON f2.id =3D ids.id
AND f2.order =3D 2
LEFT JOIN f= oo f3
ON f3.id =3D ids.id
AND f3.order =3D 3
ORDER BY ids.id;

----- Reply message -----
From: "Claudio Adriano Guarracino" &= lt;elninon@yahoo.com>
Date: Thu, May 5, 2011 5:18 pm
Subject: [SQL= ] Select and merge rows?
To: <pgsql-sql@postgresql.org>

Hel= lo!
I have a doubt about a query that I tried to do, but I cant......This is the scenario:
I have a table, with this rows:
order &nb= sp;  ID    value   
----------------= ------
1    1000    3
2  &nbs= p; 1000    5
3    1000    6=
1    1001    1
2    1001    2
1    1002    42    1002    4

I need to get this ta= ble, divided by ID, like this:
id    value1  &n= bsp; value2    value3
--------------------------------1000    3    5    6
1001&n= bsp;   1    2
1002    1 &nb= sp;  2

How I can do this?
I tried with cursors and view, but= i can't....
Any help is welcome!

Thanks in advance!
Regards,<= br>



--0-1319849445-1304643974=:41914--