I am making a query to a table to see the maximum of the id's
existing ones, but the column of id
is of type varchar
therefore since the id
last record exceeded 99 then, it detects it as the maximum, so my idea was to do that The data type is changed from varchar
to integer when you do the query so that it takes the last one id
, but the truth is I don't know and I don't have the slightest idea what to do, if someone can help me, I appreciate it.
leave the query atMySQL
$select = "SELECT max(id_controlAsis) as id FROM control_asistencias";
You can convert the data with CAST and then search for the maximum value. For a value type
int
you must do thecast
a typeunsigned
.Schema (MySQL v5.7)
Query #1
Query #2
View on DB Fiddle
What you can do, if you want to determine the maximum in a vachar field , you have to DESC order the field ** id_controlAsis ** and apply a LIMIT 1 to it, this way you get the largest value of the column and you don't have to change it to integer , I hope it helps you. Thank you
Here is the example: