开发者

Column's value as table name

开发者 https://www.devze.com 2023-03-23 10:15 出处:网络
I d开发者_Python百科on\'t have enough experience with mysql language. I need a query that include a subquery where I select something from another table with table name like a value from current table

I d开发者_Python百科on't have enough experience with mysql language. I need a query that include a subquery where I select something from another table with table name like a value from current table's column value. The query is something like this:

 SELECT * FROM `action_{$id}` as `action` INNER JOIN `{$id}` as `table` ON
    (
       (
       action.father_id='0' AND //some condition
       )
       OR
       (
            action.father_id<>'0' AND 
        table.type_id IN
        (
            SELECT type FROM **action_{$id}.father_id** WHERE type_id='{$id}'
            )
       )
    )

In this example action_{$id}.father_id(or action.father_id) contains the name of another table from my database.

Please excuse my bad english. Thank you!


No, this is not possible and indicates a structural error in your table design.

action_{$id}.father_id** WHERE type_id='{$id}'
Maybe it's just me but isn't that rather redundant?

0

精彩评论

暂无评论...
验证码 换一张
取 消