Can a subquery return a field containing the table name for the query?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Martin Davis

    #1

    Can a subquery return a field containing the table name for the query?

    I have a table with fields:
    Style_num (primary key)
    M_table_name

    If I run a subquery so that I return the value of the "M_table_na me" field for a given "Style_num" , can I use the returned value of "M_table_na me" for a query on that table? If so, how?

    Example:

    If "Style_num" value "4" has "M_table_nu m" value "AJ3", then I would like my next query to utilize the table named "AJ3".
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    Use the first query as part of the second query. For instance ...
    Query1
    Code:
    SELECT M_table_num FROM TableName WHERE Style_num = 4
    Query2
    Code:
    SELECT TableName.* FROM TableName INNER JOIN Query1
    ON TableName.M_table_num=Query1.M_table_num
    The second query will only return those records that have an M_table_num of "AJ3"

    Comment

    Working...