If the query returns a text type, but we need to obtain the numerical values of type, you can just add *1 to column you need to be int(or numeric.) Example: We have column category, in this column data has next format: 1,2,34,14,4, type of column – char, but we need get the first number and sort table by it. SELECT SUBSTRING(category,1,LOCATE(',',category)-1) ...