Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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:
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 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

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,


pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group