pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedSorting data based fields in two linked tables
3+ messages / 3 participants
[nested] [flat]
* Sorting data based fields in two linked tables
@ 2011-05-13 15:00 R. Smith <ship.quotes@gmail.com>
2011-05-14 12:58 ` Re: Sorting data based fields in two linked tables Oliver d'Azevedo Christina <oliveiros.cristina@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: R. Smith @ 2011-05-13 15:00 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Sorting data based fields in two linked tables
2011-05-13 15:00 Sorting data based fields in two linked tables R. Smith <ship.quotes@gmail.com>
@ 2011-05-14 12:58 ` Oliver d'Azevedo Christina <oliveiros.cristina@gmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: Oliver d'Azevedo Christina @ 2011-05-14 12:58 UTC (permalink / raw)
To: R. Smith <ship.quotes@gmail.com>; +Cc: pgsql-sql
Can you provide An example?
Best,
Oliveiros
Enviado via iPhone
Em 13/05/2011, às 04:00 PM, "R. Smith" <ship.quotes@gmail.com> escreveu:
> 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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [SQL] Sorting data based fields in two linked tables
@ 2011-05-14 13:54 Charlie <scorpdaddy@hotmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: Charlie @ 2011-05-14 13:54 UTC (permalink / raw)
To: R. Smith <ship.quotes@gmail.com>; pgsql-sql
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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2011-05-14 13:54 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-05-13 15:00 Sorting data based fields in two linked tables R. Smith <ship.quotes@gmail.com>
2011-05-14 12:58 ` Oliver d'Azevedo Christina <oliveiros.cristina@gmail.com>
2011-05-14 13:54 Re: [SQL] Sorting data based fields in two linked tables Charlie <scorpdaddy@hotmail.com>
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