【问题标题】:mysql match letter/number field with letter field without duplicatesmysql匹配字母/数字字段与字母字段没有重复
【发布时间】:2013-07-16 21:43:50
【问题描述】:

我在两个需要匹配的 mysql 表中有字段...在产品表中我有混合的字母/数字键 (product_code),例如 MM123,然后在集合表中我只有字母作为键 (collection_code ) 比如MM...

我试过这个:

select p.*
from product p, collection c
where p.product_code LIKE CONCAT(c.collection_code ,'%')

但是我得到了多个匹配的条目,因为 collection_code 有 M 和 MM 这样的条目,所以它返回 product_code = M123 和 product_code = MM123

我想我想要的是这样的:

select p.*
from product p, collection c
where p.product_code LIKE CONCAT(c.collection_code ,REGEXP  '[^0-9 \.]+')

但我似乎无法完全理解

【问题讨论】:

    标签: mysql regex concat


    【解决方案1】:
    SELECT p.*
    FROM product p
    JOIN collection c
    ON p.product_code REGEXP CONCAT('^', c.collection_code, '[0-9]+$')
    

    【讨论】:

      猜你喜欢
      • 2014-02-19
      • 2022-07-13
      • 2016-11-24
      • 2023-02-13
      • 2016-02-02
      • 1970-01-01
      • 1970-01-01
      • 2016-03-15
      • 2011-01-09
      相关资源
      最近更新 更多