Search code examples
mysqlfieldtype

How to return field type from MySQL query?


Simple question: How can I return the field type of a MySQL table. I know about describe or show column but I just want to return that single parameter. e.g.:

SELECT fieldtype(mycol) FROM mytable
# should return INT or integer for example

Solution

  • You can use

    SHOW FIELDS
    FROM tableName where Field ='nameOfField'
    

    This will return you result in format of

    Field   Type    Null    Key     Default     Extra