Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

select a varchar row and display only the first 3 characters

input
12345
abcde

output
123
abc
Avatar of Loganathan Natarajan
Loganathan Natarajan
Flag of India image

Do you want to use PHP or want to do in mysql itself?
Using PHP try like this,

<?php

$myStr='12345';
$result = substr($myStr, 0, 3);
echo $result;
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Peter Chan
Peter Chan
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try to do it with SQL substring() function. So that it selects only 3 char from the varchar column.
Avatar of rgb192

ASKER

This was the easiest code to use.
Thanks.