pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andy Lewis <jumboc@comcast.net>
To: 'Michael Glaesemann' <grzm@myrealbox.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: sort by on two columns
Date: Fri, 2 Jan 2004 20:55:30 -0600
Message-ID: <003a01c3d1a5$0cb603d0$0201a8c0@andy2> (raw)
In-Reply-To: <2E86574A-3D96-11D8-A298-000A95C88220@myrealbox.com>

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




view thread (6+ messages)  latest in thread

Message-ID: <003a01c3d1a5$0cb603d0$0201a8c0@andy2>
Permalink:  ../003a01c3d1a5$0cb603d0$0201a8c0@andy2/
Also on:    postgresql.org/message-id/003a01c3d1a5$0cb603d0$0201a8c0@andy2

 · 

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: jumboc@comcast.net, grzm@myrealbox.com
  Subject: Re: sort by on two columns
  In-Reply-To: <003a01c3d1a5$0cb603d0$0201a8c0@andy2>

* 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