Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

select a varchar row and display only the first 3 characters

Posted on 2013-11-05
5
Medium Priority
?
229 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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.
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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…
Suggested Courses

649 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