select a varchar row and display only the first 3 characters

input
12345
abcde

output
123
abc
LVL 1
rgb192Asked:
Who is Participating?
 
HuaMinChenConnect With a Mentor Business AnalystCommented:
Use
select substring(column1,1,3) from ...

Open in new window

0
 
Loganathan NatarajanLAMP DeveloperCommented:
Do you want to use PHP or want to do in mysql itself?
0
 
Loganathan NatarajanLAMP DeveloperCommented:
Using PHP try like this,

<?php

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

Open in new window

0
 
Loganathan NatarajanLAMP DeveloperCommented:
Try to do it with SQL substring() function. So that it selects only 3 char from the varchar column.
0
 
rgb192Author Commented:
This was the easiest code to use.
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.