Solved

select a varchar row and display only the first 3 characters

Posted on 2013-11-05
5
220 Views
Last Modified: 2013-11-07
input
12345
abcde

output
123
abc
0
Comment
Question by:rgb192
  • 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 10

Accepted Solution

by:
HuaMinChen earned 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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