pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: PipHans <piphans@hotmail.co>
To: pgsql-sql@postgresql.org
Subject: Re: Plz, what is the most "correct" method
Date: Mon, 15 Sep 2003 09:33:38 +0100
Message-ID: <200309150933.38978.dev@archonet.com> (raw)
In-Reply-To: <3f5f4af1$0$48889$edfadb0f@dtext02.news.tele.dk>
References: <3f5f4af1$0$48889$edfadb0f@dtext02.news.tele.dk>

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



view thread (2+ messages)

Message-ID: <200309150933.38978.dev@archonet.com>
Permalink:  ../200309150933.38978.dev@archonet.com/
Also on:    postgresql.org/message-id/200309150933.38978.dev@archonet.com

 · 

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: dev@archonet.com, piphans@hotmail.co
  Subject: Re: Plz, what is the most "correct" method
  In-Reply-To: <200309150933.38978.dev@archonet.com>

* 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