Reputation: 48386
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?
Upvotes: 5
Views: 13331
Reputation: 219
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.
Upvotes: 2
Reputation: 48369
Use SUBSTR
(or SUBSTRING
):
SELECT SUBSTR( 'hello', 2 );
--> 'ello'
See also: MySQL String Functions
Upvotes: 15