The INSTR() function returns the position of the first occurrence of a substring within another string. If the substring is not found, the function returns 0.
MySQL INSTR Function Syntax
SQL
x
1
INSTR(string1, string2)
MySQL INSTR Function Example
This query tries to find the position of the letter 'a'
in the first_name
of each patient:
SQL
1
1
SELECT INSTR(first_name, 'a') AS MatchPosition
2
FROM Patients;

MySQL INSTR Function Parameters
Parameter | Description |
---|---|
string1 | The string to be searched |
string2 | The substring to search for within string1 |
MySQL INSTR Function Doctors Table Example
This query tries to find the position of the letter 'e'
in each doctor’s last_name
:
SQL
1
1
SELECT INSTR(last_name, 'e') AS MatchPosition
2
FROM Doctors;

MySQL INSTR Function Notes
- Returns the position (starting at 1) of the first occurrence of a substring in another string.
- Returns 0 if the substring is not found.
- Not available in SQLite or TechKubo Playground.