Possible use of a subselect? - Mailing list pgsql-novice

From Adam Erickson
Subject Possible use of a subselect?
Date
Msg-id ALEKKHACBIAEBNBPFKPCGEPDDAAA.adamre@cox.net
Whole thread Raw
Responses Re: Possible use of a subselect?  ("Joel Burton" <joel@joelburton.com>)
Re: Possible use of a subselect?  (Manfred Koizar <mkoi-pg@aon.at>)
List pgsql-novice
Greetings All,

I've run into a spot where I think I could use a subselect but I'm not sure
how I would (or if I can).  This is a simple table which holds strings and
their translated counterparts.

Given the table structure:
string
------
id serial int4
stringid int4 not null
language varchar(32)
content varchar(255)

stringid would always equal 0 for the English version of any string.
Otherwise, it points the string.id of the English version.  Content contains
the string (or the translated version).  Language simple contains "English"
or "Chinese".

Everything is working great.  I'm trying to get a query that will return the
English version of every string ("SELECT id,content FROM STRING WHERE
language='English' and stringid=0") and their translated counterpart (say,
Korean) which would be ("SELECT content FROM string WHERE
stringid=ID.OF.ENGLISH.VERSION").

Ending up with:
| English.StringID | English String | Korean String |
-----------------------------------------------------
| 1                | Hello          | Whatever      |
| 2                | Goodbye        | NULL
         | -----------------------------------------------------
(NULL meaning that it hasn't been translated)

I could select all English strings, then select the Korean versions in a
loop but being new to postgres I thought their might be a better way?

Thanks in advance for any help,
Adam


pgsql-novice by date:

Previous
From: Ron Johnson
Date:
Subject: Re: Altering a table in Postgres to add a NOT NULL constraint
Next
From: "Joel Burton"
Date:
Subject: Re: Possible use of a subselect?