How can you return a string minus the first character in a string in MySQL?
In other words, get 'ello' from 'hello'.
The only way I can think to do it is to use mid() with the second offset being larger than the string could possibly be:
select mid('hello', 2, 99)
But I'm convinced there must be a more elegant way of doing it. Is there?
Use SUBSTR
(or SUBSTRING
):
SELECT SUBSTR( 'hello', 2 );
--> 'ello'
See also: MySQL String Functions
That is actually incorrect. If you do that, you only get llo. In order to get everything after the first character....do the following:
<?php
echo substr('hello', 1); // Output ello
echo '<br />';
echo substr('hello', 2); // Output llo
?>
I just wanted to correct that.
Edit: Bah, ignore me. I thought you were talking about in PHP. Well anyway, you can do that in Mysql..or you can just get it in PHP as I posted above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With