SELECT with column specified by subquery - Mailing list pgsql-general

From webcoyote
Subject SELECT with column specified by subquery
Date
Msg-id 1399317326878-5802533.post@n5.nabble.com
Whole thread Raw
Responses Re: SELECT with column specified by subquery
List pgsql-general
I desire to create a SELECT statement where one of the column names comes
from another table.  Something like:

  SELECT id, (SELECT type FROM favorite_food_type WHERE user = 'ralph')
  FROM foods;

If Ralph's favorite food type is fruit, ultimately I'd like the query to
become:

  SELECT id, fruit FROM foods;

Instead I get:

  SELECT id, 'fruit' FROM foods;

Where 'fruit' is a string and not treated as a column name.  Is there any
way to do this?

Thank you!



--
View this message in context:
http://postgresql.1045698.n5.nabble.com/SELECT-with-column-specified-by-subquery-tp5802533.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


pgsql-general by date:

Previous
From: DrakoRod
Date:
Subject: Re: Server continuously enters to recovery mode.
Next
From: David G Johnston
Date:
Subject: Re: SELECT with column specified by subquery