开发者

SQL Query Error ( although weird Query)

Well please check the query

Here table name is web18sso_login_a so

select table_name from information_schema.tables where table_name like '%eb18ssoa%' 

returns web18ssoa

userid is the Column in that table

now i want to get the data from the User ID with the query

select userid from (
    SELECT * from (
        select * from (
            select table_name from information_schema.tables where table_name='web18ssoa'
        ) 开发者_JAVA百科As bbc
    ) As ccv
) as nnn

the above Query says invalid userid from field list

i know i can directly use select userid from web18ssoa;

but i want to do via above query is there any other way without calling actual table getting column data from a table name

Please help me


This is how your query construct is going to work, building up from the inner query towards the outer query:

inner query:

select table_name from information_schema.tables where table_name='web18ssoa'

+------------+
| table_name |
+------------+
| web18ssoa  |
+------------+

This resultset gets aliased to bbc. You then do a select * from bbc, and alias that to ccv, then do a select username from nnn. Note that there is no "username" field in the original query result, which is why you're getting a no-such field. You're not querying the 'web18ssoa' table. You're querying a resultset which contains a row that happens have the value web18ssoa.

You cannot build a virtual query set like this.


It looks like you are under impression that the query selects from web18ssoa. In fact it does not. It ends up querying information_schema.tables. To do what you want, you need to build a dynamic query by using prepared statements

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜