pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
sort by on two columns
6+ messages / 4 participants
[nested] [flat]

* sort by on two columns
@ 2004-01-03 01:15 Andy Lewis <jumboc@comcast.net>
  2004-01-03 02:40 ` Re: sort by on two columns Michael Glaesemann <grzm@myrealbox.com>
  2004-01-03 04:05 ` Re: sort by on two columns Chris Travers <chris@travelamericas.com>
  0 siblings, 2 replies; 6+ messages in thread

From: Andy Lewis @ 2004-01-03 01:15 UTC (permalink / raw)
  To: pgsql-sql

Hi All,
Is it possible to sort by two columns? Using the query below?
 
SELECT table1.name, table2.name, <other selected columns> FROM table1,
table2 WHERE table1.id = table2.id ORDER BY <what?>
 
I want to be able to sort the names select from two different tables and
two different colums(same data type).
 
Is this possible?
 
Thanks,
 
Andy

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: sort by on two columns
  2004-01-03 01:15 sort by on two columns Andy Lewis <jumboc@comcast.net>
@ 2004-01-03 02:40 ` Michael Glaesemann <grzm@myrealbox.com>
  2004-01-03 02:55   ` Re: sort by on two columns Andy Lewis <jumboc@comcast.net>
  1 sibling, 1 reply; 6+ messages in thread

From: Michael Glaesemann @ 2004-01-03 02:40 UTC (permalink / raw)
  To: Andy Lewis <jumboc@comcast.net>; +Cc: pgsql-sql

Hi Andy,

On Jan 2, 2004, at 7:15 PM, Andy Lewis wrote:

> Is it possible to sort by two columns? Using the query below?
>
> SELECT table1.name, table2.name, <other selected columns> FROM table1,
> table2 WHERE table1.id = table2.id ORDER BY <what?>
>
> I want to be able to sort the names select from two different tables 
> and
> two different colums(same data type).


If you want to order by table1.name and table2.name, just enter them in 
a comma-separated-list after ORDER BY, e.g.,

SELECT table1.name, table2.name, <other selected columns>
FROM table1, table2
WHERE table1.id = table2.id
ORDER BY table1.name, table2.name

Check out the following link for the online docs:
<http://www.postgresql.org/docs/current/static/queries-order.html;

It doesn't explicitly give you an example of sorting on more than one 
column, but the syntax explanation at the top includes it.

Does this help?

Michael Glaesemann
grzm myrealbox com




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: sort by on two columns
  2004-01-03 01:15 sort by on two columns Andy Lewis <jumboc@comcast.net>
  2004-01-03 02:40 ` Re: sort by on two columns Michael Glaesemann <grzm@myrealbox.com>
@ 2004-01-03 02:55   ` Andy Lewis <jumboc@comcast.net>
  2004-01-03 03:04     ` Re: sort by on two columns Michael Glaesemann <grzm@myrealbox.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Andy Lewis @ 2004-01-03 02:55 UTC (permalink / raw)
  To: 'Michael Glaesemann' <grzm@myrealbox.com>; +Cc: pgsql-sql

Hi Michael,

Yes, I understand this but, I would like to have the results of both
"table1.name, table2.name"
sorted as one column.

Is this possible?

Thanks,

Andy

-----Original Message-----
From: Michael Glaesemann [mailto:grzm@myrealbox.com] 
Sent: Friday, January 02, 2004 8:40 PM
To: Andy Lewis
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] sort by on two columns


Hi Andy,

On Jan 2, 2004, at 7:15 PM, Andy Lewis wrote:

> Is it possible to sort by two columns? Using the query below?
>
> SELECT table1.name, table2.name, <other selected columns> FROM table1,

> table2 WHERE table1.id = table2.id ORDER BY <what?>
>
> I want to be able to sort the names select from two different tables
> and
> two different colums(same data type).


If you want to order by table1.name and table2.name, just enter them in 
a comma-separated-list after ORDER BY, e.g.,

SELECT table1.name, table2.name, <other selected columns>
FROM table1, table2
WHERE table1.id = table2.id
ORDER BY table1.name, table2.name

Check out the following link for the online docs:
<http://www.postgresql.org/docs/current/static/queries-order.html;

It doesn't explicitly give you an example of sorting on more than one 
column, but the syntax explanation at the top includes it.

Does this help?

Michael Glaesemann
grzm myrealbox com




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: sort by on two columns
  2004-01-03 01:15 sort by on two columns Andy Lewis <jumboc@comcast.net>
  2004-01-03 02:40 ` Re: sort by on two columns Michael Glaesemann <grzm@myrealbox.com>
  2004-01-03 02:55   ` Re: sort by on two columns Andy Lewis <jumboc@comcast.net>
@ 2004-01-03 03:04     ` Michael Glaesemann <grzm@myrealbox.com>
  2004-01-03 04:32       ` Re: sort by on two columns Adam Ruth <aruth@intercation.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Michael Glaesemann @ 2004-01-03 03:04 UTC (permalink / raw)
  To: Andy Lewis <jumboc@comcast.net>; +Cc: pgsql-sql


On Jan 2, 2004, at 8:55 PM, Andy Lewis wrote:
> Yes, I understand this but, I would like to have the results of both
> "table1.name, table2.name"
> sorted as one column.
>
> Is this possible?

So you want one column of name, including names from both table1 and 
table2? In that case, you need to use UNION, I believe. If it's 
something else, I'm not sure I understand what you're asking. Perhaps 
you could include a sample of what you're getting, along with what 
you'd like to see?

Michael Glaesemann
grzm myrealbox com




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: sort by on two columns
  2004-01-03 01:15 sort by on two columns Andy Lewis <jumboc@comcast.net>
  2004-01-03 02:40 ` Re: sort by on two columns Michael Glaesemann <grzm@myrealbox.com>
  2004-01-03 02:55   ` Re: sort by on two columns Andy Lewis <jumboc@comcast.net>
  2004-01-03 03:04     ` Re: sort by on two columns Michael Glaesemann <grzm@myrealbox.com>
@ 2004-01-03 04:32       ` Adam Ruth <aruth@intercation.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Adam Ruth @ 2004-01-03 04:32 UTC (permalink / raw)
  To: Michael Glaesemann <grzm@myrealbox.com>; +Cc: Andy Lewis <jumboc@comcast.net>; pgsql-sql

Sounds like you may want to concatenate the columns:

... order by table1.name || table2.name

The sorting would then be performed on both of the them as though they 
were one column.

Adam Ruth

On Jan 2, 2004, at 8:04 PM, Michael Glaesemann wrote:

>
> On Jan 2, 2004, at 8:55 PM, Andy Lewis wrote:
>> Yes, I understand this but, I would like to have the results of both
>> "table1.name, table2.name"
>> sorted as one column.
>>
>> Is this possible?
>
> So you want one column of name, including names from both table1 and 
> table2? In that case, you need to use UNION, I believe. If it's 
> something else, I'm not sure I understand what you're asking. Perhaps 
> you could include a sample of what you're getting, along with what 
> you'd like to see?
>
> Michael Glaesemann
> grzm myrealbox com
>
>
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: sort by on two columns
  2004-01-03 01:15 sort by on two columns Andy Lewis <jumboc@comcast.net>
@ 2004-01-03 04:05 ` Chris Travers <chris@travelamericas.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Chris Travers @ 2004-01-03 04:05 UTC (permalink / raw)
  To: Andy Lewis <jumboc@comcast.net>; pgsql-sql

MessageSELECT * FROM customers ORDER BY last_name, first_name
Works for me.
  ----- Original Message ----- 
  From: Andy Lewis 
  To: pgsql-sql@postgresql.org 
  Sent: Saturday, January 03, 2004 8:15 AM
  Subject: [SQL] sort by on two columns


  Hi All,
  Is it possible to sort by two columns? Using the query below?

  SELECT table1.name, table2.name, <other selected columns> FROM table1, table2 WHERE table1.id = table2.id ORDER BY <what?>

  I want to be able to sort the names select from two different tables and two different colums(same data type).

  Is this possible?

  Thanks,

  Andy

^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2004-01-03 04:32 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-01-03 01:15 sort by on two columns Andy Lewis <jumboc@comcast.net>
2004-01-03 02:40 ` Michael Glaesemann <grzm@myrealbox.com>
2004-01-03 02:55   ` Andy Lewis <jumboc@comcast.net>
2004-01-03 03:04     ` Michael Glaesemann <grzm@myrealbox.com>
2004-01-03 04:32       ` Adam Ruth <aruth@intercation.com>
2004-01-03 04:05 ` Chris Travers <chris@travelamericas.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