Is is possible to get the column types and names from a select statement in MySQL?


SELECT t.first_col, t.third_col
FROM my_table t
WHERE t.id = 1

And then I would send that to MySQL and have it tell me.

column_name  |  type     | length
first_col    |  varchar  | 5
third_col    |  int      | null

I know I can do it in SQL Server I was hoping I can do it in MySQL too.

1 Answer 1


Why is that Questions come in pairs? This recent one discussed the solution you want:

MySQL data precision confusion

  • I'm actually looking to get the metadata of the query. Not table metadata.
    – Jon49
    Commented Aug 30, 2017 at 2:07
  • 1
    Sorry, no such info. EXPLAIN FORMAT=JSON SELECT ... gives you some info, but not specifically what you asked for.
    – Rick James
    Commented Aug 30, 2017 at 4:07
  • I saw that MySQL has support for CTEs so I thought maybe they would be able to support some type inference for a SELECT statement.
    – Jon49
    Commented Aug 30, 2017 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.