Using Substring in MySQL criteria

I'm trying to fetch all instances where the 1st letter of a person's first name is equal to P.

This is what I came up with, which doesn't return anything:

$sql="SELECT * FROM people WHERE SUBSTRING(FirstName,0,1) = 'P'";

Suggestions?

Answers


The reason your expression doesn't work is that substring() positions are 1-based

Try either of these:

where FirstName like 'P%'

or

where substring(FirstName,1,1) = 'P'

Need Your Help

Bootstrap navbar-toggler-icon not visible but functioning normally

html css twitter-bootstrap handlebars.js

I am trying to get my bootstrap navbar implemented into my handlebars layout file. I've noticed some weird things happening with bootstrap and this is no exception. Once I shrink my window to a size

IntelliJ Idea auto create new method

java android-studio intellij-idea

In eclipse, I can just move the mouse on a new method name and click to create a new method. I wonder how can I do it with Android studio (which is based on IntelliJ Idea).