From: | Nabil Sayegh <nas(at)e-trolley(dot)de> |
---|---|
To: | "Luis H(dot)" <pgsql-novice(at)geekhouse(dot)no-ip(dot)com> |
Cc: | pgsql-novice <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: ORDER BY question |
Date: | 2003-09-01 07:57:00 |
Message-ID: | 1062403020.32576.4.camel@billy |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Am Mo, 2003-09-01 um 03.44 schrieb Luis H.:
> I have two tables, table A contains users (id, username, password) , and
> table B contains a row that signifies the 'owner' of each particular entry,
> referencing an id in A.
>
> so example
>
> table A
> id username password
> ------------------------
> 1 me *****
> 2 you *******
>
> table B
> description owner
> -------------------------
> 'something cool' 2
> 'another thing' 1
>
>
> What I want to do is do a query where I order table B by owner, but
> alphabetically by username. The problem, obviously, is that table B only
> contains id's (numbers, indexing to A), which don't correspond to the
> alphabetical order of the usernames.
SELECT * FROM a JOIN b ON (a.id=b.owner) ORDER BY a.username
or
SELECT * FROM a, b WHERE a.id=b.owner ORDER BY a.username
If you had the columnnames the same in A and B for the id you could do:
SELECT * FROM a JOIN B USING (id_a) ORDER BY a.username
> I'm not very familiar with subqueries, but I expect I should be able to
> somehow select ID's from table A ordered by username, and use this index to
> order table B by owner.
No need for subselects here
--
e-Trolley Sayegh & John, Nabil Sayegh
Tel.: 0700 etrolley /// 0700 38765539
Fax.: +49 69 8299381-8
PGP : http://www.e-trolley.de
From | Date | Subject | |
---|---|---|---|
Next Message | Luis H. | 2003-09-01 13:57:04 | Re: ORDER BY question |
Previous Message | Bruno Wolff III | 2003-09-01 07:04:36 | Re: ORDER BY question |