UPDATE mytable SET mycolumn= LTRIM(RTRIM(mycolumn));
i use this to trim entire column from leading and trailing space,but what i want is
|ID|Name |
|1 |demo 6 |
|2 |demo3 500 |
what i want is to trim NAME where last char is int by removing this int.
output
|ID|Name |
|1 |demo |
|2 |demo |
is it doable with mysql alone ? or i will need to use php to update table ?
note: this table contain around 20K row
Edit: ok php it is,
$s='';
foreach($q as $row){
$d=$row->name;
while(is_numeric(substr($d,-1))){$d=rtrim($d, '0123456789');}
if(is_numeric(substr($row->name,-1)))
$s.="update name_list set name='".$d."' where id='{$row->id}';\n";
}
echo "count:".count(explode('\n',$s))."<br/><pre>$s</pre>";
if i try to run them one by one it runout..
is there a better way to patch update rows?