Sending multiple fields per product to new table

Hi!

I have a table of products called ‘products’ like:

| id | name | desc | price | supplierId | barcode1 | barcode2 | barcode3 | barcode4 | etc…

Some products have as many as 10 different barcodes. Obviously this is a ridiculous setup of barcodes (imported from supplier price lists) which I would like send to their own table called ‘barcodes’ like:

| productId | barcode |

(where productId is matched to that in the ‘products’ table - products.id)

Then each barcode can be slit into their own entries.

Thing is I have thousands of products. Any idea on how I can do this in bulk? I don’t really know where to start!

Cheers!

You could run 10 queries like this (changing the barcode field):


INSERT INTO barcodes
SELECT 
    id
  , barcode1
FROM products
WHERE barcode1 <> ''
AND barcode1 IS NOT NULL

Excellent, cheers guido!