Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 7423FB5DBB6 for ; Sat, 14 May 2011 09:59:10 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 14696-09 for ; Sat, 14 May 2011 12:59:01 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ww0-f42.google.com (mail-ww0-f42.google.com [74.125.82.42]) by mail.postgresql.org (Postfix) with ESMTP id 4E96EB5D95B for ; Sat, 14 May 2011 09:59:01 -0300 (ADT) Received: by wwk4 with SMTP id 4so1361634wwk.1 for ; Sat, 14 May 2011 05:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:references:in-reply-to:mime-version :content-transfer-encoding:content-type:message-id:cc:x-mailer:from :subject:date:to; bh=wPreQk9EjajjQj/CItWBNiFX3OD+U7XHN/LsMv8lFw0=; b=Y158EXex4IZwqLi9h3bnjSpwLIGyhioO5nGeAfMAk24JtrbMR155PTROpyaG0jXaQm I1fUCFyPLEq1bhA+VNctD/uJApcTaPpGbwSctF6/ixKmyEbzPdwsaEy34gwITP7Boyjs OZkDepldtB3Q9WkPsZEegywIePi+LnR81SANM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=references:in-reply-to:mime-version:content-transfer-encoding :content-type:message-id:cc:x-mailer:from:subject:date:to; b=svTmrRoZq4JIUTi2Oc+JG3uNXPYktuEnkatas+yIkmr2lUJLJxJx31hly3v+cMHDB8 A4sPxNKGPUS9E/SNKQ9s2bRGn86FMQHgi24wQoX+3ke7Fa+XQwv9nn5nImlwmX2qIWSi REzEjeEGo8LdDC2wwFwCiHdi7/ZK/SikR8We8= Received: by 10.227.164.202 with SMTP id f10mr2569455wby.92.1305377939040; Sat, 14 May 2011 05:58:59 -0700 (PDT) Received: from [192.168.1.100] ([213.63.110.3]) by mx.google.com with ESMTPS id bs4sm1965815wbb.35.2011.05.14.05.58.57 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 14 May 2011 05:58:57 -0700 (PDT) References: In-Reply-To: Mime-Version: 1.0 (iPhone Mail 8G4) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Message-Id: <578F5EAE-5567-4254-AE34-380B249E8F63@gmail.com> Cc: "pgsql-sql@postgresql.org" X-Mailer: iPhone Mail (8G4) From: Oliver d'Azevedo Christina Subject: Re: Sorting data based fields in two linked tables Date: Sat, 14 May 2011 13:58:54 +0100 To: "R. Smith" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.897 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, MIME_QP_LONG_LINE=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201105/89 X-Sequence-Number: 35373 Can you provide An example? Best, Oliveiros Enviado via iPhone Em 13/05/2011, =C3=A0s 04:00 PM, "R. Smith" escreveu= : > Hi, >=20 > I am looking for a way to sort data returned from two tables with the > first sort based on a field from table A and the secord sort based on > the results of the first sort but the sort field is from table B. > While I can sort on either fields from either table, I cannot get it > to work on both. I have tried a crosstab query, but this a fails as > the number of rows returned from TABLE B for each row in TABLE A is an > unknown. I tried creating a temporary table, to then sort on, but this > failed as well. Example layout below: >=20 > Table A >=20 > ID FIELD1 FIELD2 >=20 > Table B >=20 > ID, A.ID FIELD1,FIELD2 >=20 > Output Based on sorting A.FIELD2, then B.FIELD1 >=20 > A.ID,A.FIELD1,A.FIELD2, B.FIELD1,B.FIELD2, B.FIELD1,B.FIELD2, B.FIELD1,B.= FIELD2 >=20 > Can anyone help me with this? >=20 > Regards >=20 > --=20 > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql