pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Charlie <scorpdaddy@hotmail.com>
To: R. Smith <ship.quotes@gmail.com>
To: pgsql-sql@postgresql.org
Subject:  Re: [SQL] Sorting data based fields in two linked tables
Date: Sat, 14 May 2011 10:54:10 -0300
Message-ID: <BLU0-SMTP146E258C929D7ABA53C7C6BCE8B0@phx.gbl> (raw)

SELECT

A.ID,A.FIELD1,A.FIELD2,  B.FIELD1,B.FIELD2, B.FIELD1,B.FIELD2, B.FIELD1,B.FIELD2

FROM a
INNER JOIN B
ON a.id = b.a_id 
ORDER BY a.field2 ASC, b.field1 ASC ;


----- Reply message -----
From: "R. Smith" <ship.quotes@gmail.com>
Date: Fri, May 13, 2011 12:00 pm
Subject: [SQL] Sorting data based fields in two linked tables
To: <pgsql-sql@postgresql.org>

Hi,

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:

Table A

ID FIELD1 FIELD2

Table B

ID, A.ID FIELD1,FIELD2

Output Based on sorting A.FIELD2, then B.FIELD1

A.ID,A.FIELD1,A.FIELD2,  B.FIELD1,B.FIELD2, B.FIELD1,B.FIELD2, B.FIELD1,B.FIELD2

Can anyone help me with this?

Regards

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



view thread (3+ messages)

Message-ID: <BLU0-SMTP146E258C929D7ABA53C7C6BCE8B0@phx.gbl>
Permalink:  ../BLU0-SMTP146E258C929D7ABA53C7C6BCE8B0@phx.gbl/
Also on:    postgresql.org/message-id/BLU0-SMTP146E258C929D7ABA53C7C6BCE8B0@phx.gbl

 · 

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: scorpdaddy@hotmail.com, ship.quotes@gmail.com
  Subject: Re:  Re: [SQL] Sorting data based fields in two linked tables
  In-Reply-To: <BLU0-SMTP146E258C929D7ABA53C7C6BCE8B0@phx.gbl>

* 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