I have two tables that I want to join. The problem is, the data needs some trimming.
== 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
I want to join these tables on the SKU. However I need to do a replace since I don’t think a LIKE or % would be accurate enough?
Use
locate('_', sku)gets the position of the_in your stringsubstring(sku, 1, locate('_', sku)+1)extracts a substring fromsku. The substring will start at position1and end at the position before_. That is why-1is used.SQLFiddle demo