Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Substring return empty value

SELECT SUBSTRING(FieldName,0,20) FROM Table 

I try on phpmyadmin and returned empty value. How i use this function ?

like image 456
Awersione Avatar asked Dec 05 '11 14:12

Awersione


2 Answers

The SUBSTR start index is 1 in mysql. So, you should change your code to:

SELECT SUBSTR(FieldName,1,20) FROM TABLE; 

Notice that SUBSTR() is a synonym for SUBSTRING() so they can be used interchangeably.

You should also checkout the documentation for SUBSTRING()

like image 197
Cyclonecode Avatar answered Sep 25 '22 17:09

Cyclonecode


you must use SELECT SUBSTRING(FieldName,1,20) FROM Table, because from 0 is 0 :)

use 1

ups, someone wrote answer faster than I :)

like image 34
Tvitmsvleli Avatar answered Sep 21 '22 17:09

Tvitmsvleli