auto increment - Using a SELECT query as column name in MySQL -



values of auto_increment column in table (example). catch however, don't have name of auto_increment field. i'm using following query determine name of field:

select column_name information_schema.columns table_name = 'example' , = 'auto_increment' limit 1; 

i pass result of query, 'string' actual query, , value. if in 1 go, how that, because below query, should give me auto_increment values used, yields above result -namely auto_increment column name.

select (    select column_name    information_schema.columns    table_name =  'example'    , =  'auto_increment'    limit 1 ) pri example  

any thoughts appreciated :)
many regards,

andreas

here example of how using prepare , execute:

select @s := concat('select `', column_name, '` example e') information_schema.columns table_name =  'example' , =  'auto_increment' limit 1  prepare stmt @s; execute stmt; deallocate prepare stmt; 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -