Possible use of a subselect?

From: "Adam Erickson" <adamre(at)cox(dot)net>
To: "Pgsql-Novice" <pgsql-novice(at)postgresql(dot)org>
Subject: Possible use of a subselect?
Date: 2002-05-27 04:43:50
Message-ID: ALEKKHACBIAEBNBPFKPCGEPDDAAA.adamre@cox.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Joel Burton 2002-05-27 06:21:54 Re: Possible use of a subselect?
Previous Message Ron Johnson 2002-05-27 00:35:40 Re: Altering a table in Postgres to add a NOT NULL constraint