I am using mysql. Still learning things about it.
I have a table that has a column called UPC that is char(13)
I am finding that there are records where there are patterns like:
4009426030
04009426030
Having UPCs like those above means I have two records for the same item. I need to find all the records that are the same so I can merge them. So I tried
SELECT *
FROM products p1
WHERE prod_id in (
SELECT prod_id
FROM products p2
WHERE lpad(p2.upc, 13, '0') = lpad(p1.upc, 13, '0')
AND p2.upc != p1.upc
)
My idea was that I would find the records where '4009426030' != '04009426030' but '0004009426030' == '0004009426030' so I don't match on the same records, only different ones.
But I get no results! Can someone see what I am doing wrong?