[英]select where start from first not substr mysql
I tried to make a research but just from prefixe. 我试图进行研究,但只是从前缀开始。
Eg. 例如。 when I search
10542
, 110542
shouldn't be there, just 105428001
. 当我搜索
10542
, 110542
不应该有,只是105428001
。
The string : 字符串:
110542004
105428001
I tried 我试过了
LEFT(INV.INV_CD,5) LIKE '%".$option3."%'";
and 和
SUBSTRING(INV.INV_CD,1,5) LIKE '%".$option3."%'";
Both result are the same. 两者的结果是相同的。
The problem is your LIKE
syntax : 问题是您的
LIKE
语法:
LIKE '%".$option3."%'";
When you use %
it means you can have something at the same place, so LIKE '%".$option3."%'";
you can return value with XXXX + $option3 + XXXX
(with XXXX
equal to nothing or multiple char) 当您使用
%
,意味着您可以在同一位置放东西,所以LIKE '%".$option3."%'";
可以用XXXX + $option3 + XXXX
(其中XXXX
等于零或多个字符)返回值
If you only want $option3 + XXXX
, just write LIKE '".$option3."%'";
如果只需要
$option3 + XXXX
,则只需输入LIKE '".$option3."%'";
Here is the documentation about this : 这是关于此的文档 :
With LIKE you can use the following two wildcard characters in the pattern:
使用LIKE,可以在模式中使用以下两个通配符:
% matches any number of characters, even zero characters.
%匹配任意数量的字符,甚至零个字符。
_ matches exactly one character.
_恰好匹配一个字符。
When you have a % in your like clause, this allows any characters, so one at the begining allows it to start anywhere. 当like子句中包含%时,它允许任何字符,因此开头的一个字符允许它在任何地方开始。 Remove it to start at the begning...
删除它以开始...
INV.INV_CD LIKE '".$option3."%'";
Note: You should also try to use prepared statements as they can stop a lot of problems in the future! 注意:您还应该尝试使用准备好的语句,因为它们将来可能会阻止很多问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.