我可以在MySQL查询中使用preg_replace或regex吗?

我可以在MySQL查询中使用preg_replace或regex吗?,mysql,sql,inner-join,Mysql,Sql,Inner Join,我有两个表要加入。问题是,数据需要一些修整 == Product Description id sku price 1 674_orange 45.99 2 645_black 59.99 5 592_rubyred 69.99 == Product Attributes id

我有两个表要加入。问题是,数据需要一些修整

== Product Description

id              sku                 price

1               674_orange          45.99
2               645_black           59.99
5               592_rubyred         69.99

== Product Attributes

id          sku     description

11          674     lorem ipsum long text description of 674
22          645     lorem ipsum keywords for this item
33          592     lorem ipsum colours on this item
我想在SKU上加入这些表。但是,我需要做一个替换,因为我认为像
%
这样的
不够准确?

使用

select *
from description d
join attributes a on a.sku = substring(sku, 1, locate('_', sku)-1)
locate(“”,sku)
获取字符串中
的位置

子字符串(sku,1,定位(“,sku)+1)
sku
中提取子字符串。子字符串将从位置
1
开始,并在
之前的位置结束。这就是为什么使用
-1

使用

select *
from description d
join attributes a on a.sku = substring(sku, 1, locate('_', sku)-1)
locate(“”,sku)
获取字符串中
的位置

子字符串(sku,1,定位(“,sku)+1)
sku
中提取子字符串。子字符串将从位置
1
开始,并在
之前的位置结束。这就是为什么使用
-1

试试这个:

SELECT * FROM ProductDescription pd 
INNER JOIN ProductAttributes pa ON SUBSTRING_INDEX(pd.sku, '_', 1) = pa.sku ;
试试这个:

SELECT * FROM ProductDescription pd 
INNER JOIN ProductAttributes pa ON SUBSTRING_INDEX(pd.sku, '_', 1) = pa.sku ;

谢谢,你能解释一下吗?非常感谢。谢谢,你能解释一下吗?非常感谢。可能重复的可能重复的可能重复的。谢谢你的回答。谢谢你的回答