开发者

Mysql query - how to force sign "_" in pattern matching?

开发者 https://www.devze.com 2023-04-12 16:00 出处:网络
I have in database TEST these values for example: ID 1_0 1_1 10_1 11_1 If I want select all values ​​at the beginning with number \"1\", but not \"10\" or \"11\" then I have created my request in

I have in database TEST these values for example:

ID
1_0    
1_1
10_1
11_1

If I want select all values ​​at the beginning with number "1", but not "10" or "11" then I have created my request in that way:

SELECT * F开发者_开发知识库ROM test WHERE id LIKE '1_%';

But sign _ for Mysql Query also means one character from name so result of this will be all the values from the list.

My question is - how to force query to think that _ is a character in ID name, not sign of any letter?


I think you should be able to just escape the _ like so:

SELECT * FROM test WHERE id LIKE '1\_%';
0

精彩评论

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

关注公众号