我有一个要查找的完整商品代码,'34FDE353UE2'
,以及一个装有所述商品代码的简化版本的表格,例如
itemCode
============
34FDE
35DCF
34FPE
....
我如何查看我的行以查看它们是否与'34FDE353UE2'
相匹配?在我的示例中,我希望返回第一行,因为34FDE
是'34FDE353UE2'
的子字符串。如何编写查询来做到这一点?
使用MySQL 5.6。
答案 0 :(得分:5)
使用like
:
select * from tablename
where '34FDE353UE2' like concat(itemCode, '%')
这将返回行,其中itemCode的值是'34FDE353UE2'
的起始字符。
如果您希望其中itemcode
是'34FDE353UE2'
的子字符串的行,则:
select * from tablename
where '34FDE353UE2' like concat('%', itemCode, '%')
答案 1 :(得分:0)
这将起作用:
select * from tablename where REGEXP_SUBSTR(itemCode,'34FDE353UE2')