Re: Plz, what is the most "correct" method

From: Richard Huxton <dev(at)archonet(dot)com>
To: "PipHans" <piphans(at)hotmail(dot)co>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Plz, what is the most "correct" method
Date: 2003-09-15 08:33:38
Message-ID: 200309150933.38978.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wednesday 10 September 2003 17:01, PipHans wrote:
> Table1:
> id Auto,int,PrimKey
> table2id int
> txt nvarchar50
>
> Table2:
> id Auto,int,PrimKey
> order int
>
> The scenario: Table2.order defines how the table1.txt is should be ordered.
> Table1.table2id contains the id of the order. This cannot be changed
>
> How do I select all Table1.txt values but ordered by their corresponding
> values of the table2.order field?

Sorry for the delay here - are you subscribed to the list? If not that can
slow things down (it only showed Monday, after you posted Wednesday).

All you need to do is join the two tables and order by the required field

SELECT t1.id, t1.txt FROM table1 as t1, table2 as t2
WHERE t1.table2id=t2.id
ORDER BY t2.order

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Sydney-Smith 2003-09-15 08:57:07 Copy Command Error
Previous Message A.Bhuvaneswaran 2003-09-15 04:57:31 Re: change a field