MYSQL Tutorial

MySQL POSITION() function

POSITION() function

MySQL POSITION() returns the position of a substring within a string.


POSITION(substr IN str)


Name Description
substr A string whose position within another string (str) is to be retrieved.
IN Keyword.
str A string within which the position of the substring (substr) is to be retrieved.

The above function is a synonym for LOCATE(substr,str).

MySQL Version: 5.6

Video Presentation

Pictorial Presentation

MySQL POSITION() pictorial presentation

Example: MySQL POSITION() function

The following MySQL statement returns the position of the substring ‘ou’ within the string ‘w3resource’


>SELECT POSITION("ou" IN "w3resource"); 

Sample Output:

mysql> SELECT POSITION("ou" IN "w3resource"); 
| POSITION("ou" IN "w3resource") |
|                              6 | 
1 row in set (0.01 sec)

All String Functions

MySQL String Functions, slide presentation

Many of our valued users post comments along with piece of code. Disqus may, false positively, consider those piece of code as Bad or Starnge syntax and send those comments to spam automatically. Even if that happens, we will make sure those useful comments are taken out of spam and approved. It may take a couple of days for that though, but any useful comment will be brought to public view for sure. We regret if that happend to any user. You may write us directly regarding this to - w3resource[at]yahoo[dot]com.