MAX() and MIN() problem in PDO query


 $maxmin = $db->prepare("SELECT MIN(length(daire_sayisi)) as minabone, MAX(length(daire_sayisi)) as maxabone FROM multiswitch" );
 $maxmin_abone = $maxmin->fetch(PDO::FETCH_ASSOC);
 echo $maxmin_abone['minabone'];
 echo "<br />";
 echo $maxmin_abone['maxabone'];

This is the column structure of “daire_sayisi varchar(11) utf8_general_ci

This column has values “8,12,16,…152,156,160”
I want to get values 8 and 160 here but I get two 1s and two 3s

Note: The type of column “daire_sayisi” must be varchar

I solved the problem as below

MIN(cast(daire_sayisi AS SIGNED)) as minabone, MAX(cast(daire_sayisi AS SIGNED)) as maxabone

Did you look up what LENGTH() does - MySQL :: MySQL 8.0 Reference Manual :: 12.8 String Functions and Operators

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service