?
Solved

select a varchar row and display only the first 3 characters

Posted on 2013-11-05
5
Medium Priority
?
225 Views
Last Modified: 2013-11-07
input
12345
abcde

output
123
abc
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 39623686
Do you want to use PHP or want to do in mysql itself?
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 39623693
Using PHP try like this,

<?php

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

Open in new window

0
 
LVL 11

Accepted Solution

by:
HuaMinChen earned 2000 total points
ID: 39623696
Use
select substring(column1,1,3) from ...

Open in new window

0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 39623711
Try to do it with SQL substring() function. So that it selects only 3 char from the varchar column.
0
 

Author Closing Comment

by:rgb192
ID: 39629605
This was the easiest code to use.
Thanks.
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question