pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Proper SQL syntax requested
2+ messages / 2 participants
[nested] [flat]

* Proper SQL syntax requested
@ 2004-04-21 23:41 Blake <blake@shopwhatcom.com>
  2004-04-27 12:06 ` Re: Proper SQL syntax requested Richard Huxton <dev@archonet.com>
  0 siblings, 1 reply; 2+ messages in thread

From: blake@shopwhatcom.com @ 2004-04-21 23:41 UTC (permalink / raw)
  To: pgsql-sql

Wondering if anyone can help me with the proper syntax for an ORDER BY
clause with a subquery. What I have is a table column named make in
one table. The make column contains a Serial ID of the name which is
stored in an alternate table named sections. I am trying to be able to
ORDER by on make, but as you can guess it is ORDERING by the ID rather
than the actual Name.

Select * from floors Where system = 1 ORDER by make

This sorts by the Serial ID's in column make

I would like to be able to sort by the actual Names associated back
from the ID's. Anyway of doing this??

Thanks All for the Help!



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

* Re: Proper SQL syntax requested
  2004-04-21 23:41 Proper SQL syntax requested Blake <blake@shopwhatcom.com>
@ 2004-04-27 12:06 ` Richard Huxton <dev@archonet.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Richard Huxton @ 2004-04-27 12:06 UTC (permalink / raw)
  To: blake@shopwhatcom.com; pgsql-sql

On Thursday 22 April 2004 00:41, Blake wrote:
>
> Select * from floors Where system = 1 ORDER by make
>
> This sorts by the Serial ID's in column make
>
> I would like to be able to sort by the actual Names associated back
> from the ID's. Anyway of doing this??

You don't say which table contains the name in question. Assuming we want 
column make_name from table make_description with an id of make_id then:

SELECT floors.* FROM floors, make_description 
WHERE system=1 AND floors.make = make_description.make_id
ORDER BY make_description.make_name;

This is called a join. Any book on databases/SQL should discuss this sort of 
stuff.

-- 
  Richard Huxton
  Archonet Ltd



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


end of thread, other threads:[~2004-04-27 12:06 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-04-21 23:41 Proper SQL syntax requested Blake <blake@shopwhatcom.com>
2004-04-27 12:06 ` Richard Huxton <dev@archonet.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