How do I make a sql query where fields are the result of a different query?

Posted by CRP on Stack Overflow See other posts from Stack Overflow or by CRP
Published on 2010-03-25T15:46:27Z Indexed on 2010/03/25 15:53 UTC
Read the original article Hit count: 240

Filed under:

I have two tables,

the first is like this:

f1 | f2 | f3 | f4
-----------------
data....

the second contains info about the fields of the first:

field | info
------------
 f1      a
 f2      b
 f3      a
etc.

I would like to query the first table selecting the fields with a query on the second. So, for example, I might want to get data for fields where info is equal to "a", thus I would do "select f1, f3 from first_table". How do I do this programmatically? I was thinking about something along the lines of select (select fields from second_table where info='a') from first_table

Thanks Chris

© Stack Overflow or respective owner

Related posts about sql