[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

select a varchar row and display only the first 3 characters

input
12345
abcde

output
123
abc
0
rgb192
Asked:
rgb192
  • 3
1 Solution
 
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
 
HuaMinChenBusiness AnalystCommented:
Use
select substring(column1,1,3) from ...

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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now