Search code examples
mysqlsqldatatypes

Add different value types to mysql tables' columns


Is there any way to add different types of values in the SAME column in a MySQL table?

EDIT: Every row has a varchar data field in a column that has a numerical value associated to it in another field in another column. Is it possible to save these numbers as float type in some rows and int in some others?


Solution

  • It takes 3 columns:

    (Int)     (Int)      (Float)
    IsInt     IntVal     FloatVal
    1         14         NULL
    1         2011       NULL
    0         NULL       23.33
    0         NULL       2.5
    1         13         NULL
    1         42         NULL
    

    Then you can check the IsInt field to see which data type you used.