SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot maffp's Avatar
    Join Date
    Jun 2005
    Location
    UK
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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!

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    You could run 10 queries like this (changing the barcode field):
    Code MySQL:
    INSERT INTO barcodes
    SELECT 
        id
      , barcode1
    FROM products
    WHERE barcode1 <> ''
    AND barcode1 IS NOT NULL

  3. #3
    SitePoint Zealot maffp's Avatar
    Join Date
    Jun 2005
    Location
    UK
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent, cheers guido!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •