开发者

Using Substring in MySQL criteria

开发者 https://www.devze.com 2023-02-18 09:40 出处:网络
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:

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开发者_StackOverflow中文版) = 'P'";

Suggestions?


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'
0

精彩评论

暂无评论...
验证码 换一张
取 消