you are at Encyclopedia of SQL >> SUBSTRING
SUBSTRING(`column_name`,position [,number_of_characters] )
This fucntion is used to operate on text strings in results of query.
Third parameter is optional.
SUBSTRING(`column_name`,position [,number_of_characters])
`column_name` - text string to be trimed
position - starting position to trim
number_of_characters - optional parameter, amount of characters to trim
In Oracle there is used SUBSTR() and in some MySQL versions
In MS Access there is MID().
Syntax
SELECT SUBSTRING(`column_name`, position[,number_of_characters])
FROM `table_name`
WHERE `table_name` operator 'value'
Example
Display first two letters from surname
name | surname | age |
Paweł | Kowalski | 3 |
Piotr | Janik | 7 |
Michał | Nowak | 13 |
query
SELECT SUBSTRING(`surname`, 1,2)
FROM `people`
result
SUBSTRING(`surname`) |
Ko |
Ja |
No |
[ wróć na górę strony ]