How does one embed a sub-query lookup to one table in order to
replace a foreign key id number with it's name in a SELECT on a
second table?
i.e.: given the following two tables, I want to replace the color_id
of 1
with the color_name 'red.' (The SQL to create the two tables follows
below.)
tes
something == otherthing is a boolean expression, you are asking the
database to compare both values, u.color_id is not equal c.color_name,
that's why you get 'f'.
I guess that you want to replace the color_id from users by the
corresponding color_name from colors:
SELECT
c.color_name, u.nam
Scott Frankel <[EMAIL PROTECTED]> writes:
> Here's my query:
> SELECT (
> u.color_id = (
> SELECT c.color_name
> FROM colors c
> WHERE color_id = 1)) AS color_name,
> u.name, u.the_date
> FROM users u
>WHERE
On Fri, Nov 12, 2004 at 09:52:09AM -0800, Scott Frankel wrote:
>
> How does one embed a sub-query lookup to one table in order to
> replace a foreign key id number with it's name in a SELECT on a
> second table?
You're talking about joins.
http://www.postgresql.org/docs/7.4/static/tutorial-join.
On Fri, Nov 12, 2004 at 11:26:14AM -0700, Michael Fuhr wrote:
> There are at least four ways to write the join query you want:
I may have misunderstood what results you're looking for, but the
examples I gave may nevertheless be useful. Sorry if they cause
any confusion.
--
Michael Fuhr
http:/
Cooking with gas once again ;) Thanks for the info on JOINs!
Scott
On Nov 12, 2004, at 9:52 AM, Scott Frankel wrote:
How does one embed a sub-query lookup to one table in order to
replace a foreign key id number with it's name in a SELECT on a
second table?
i.e.: given the following two tables,