2

I am trying to update my product database and find duplicates after some product numbers were simplified.

Here is what I am trying that is not working:

SELECT b.Id as OLDID, c.Id as NEWID
FROM productdata b, productdata c
WHERE b.ProdNum REGEXP CONCAT('^', c.ProdNum, '(\-|\s)[a-zA-Z0-9]+(\-|\s)[a-zA-Z0-9]+')

Old Product number: WR-101 3 Day (as well as WR-101 1 Day, etc.)

New Product number: WR-101

So basically I need a where clause that will match up the new Product number with the old product number that had "1 Day", "3 Day" etc. on them.

Thanks for your help.

1
  • I know the REGEX is more complex than it needs to be, but I ok with the extra resources and I want one that can catch more than this specific problem. Commented Mar 6, 2013 at 0:04

1 Answer 1

3

MySQL's regex flavor does not support \s for spaces. You need to use [[:space:]]. You also don't need to escape the dash:

(-|[[:space:]])[a-zA-Z0-9]+(-|[[:space:]])[a-zA-Z0-9]+
Sign up to request clarification or add additional context in comments.

1 Comment

+1 You can further simplify with [-[:space:]] instead of (-|[[:space:]])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.