need with my sql query

Discussion in 'MySQL' started by Goonline, Oct 4, 2008.

  1. #1
    I have products table in mysql DB

    i want to add files name in 3 diffrent fields

    I already have product id for this products

    And i need to add fields only from one product id to another

    I tried


    insert into products
    ('products_image','products_image_med','products_image_lrg')
    VALUES
    ('3a_s.jpg','3a_s.jpg','3a_s.jpg'),
    ('4a_s.jpg','4a_s.jpg','4a_s.jpg'),
    ('5a_b.jpg','5a_b.jpg','5a_b.jpg'),

    WHERE products_id >1806 AND products_id < 2642

    Not working


    Thank you
    Good day
     
    Goonline, Oct 4, 2008 IP
  2. Goonline

    Goonline Well-Known Member

    Messages:
    239
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    130
    #2
    need help thank you
     
    Goonline, Oct 4, 2008 IP
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    1. Don't bump after only 2 hours
    2. Read up on SQL, you are way off

    The errors you are getting should indicate some problems, such as:
    - not using backticks for column names
    - trailing comma at end of list
    - a 'where' clause in an 'insert' query

    I think you want to do an 'update' query.
     
    krt, Oct 4, 2008 IP
  4. Goonline

    Goonline Well-Known Member

    Messages:
    239
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    130
    #4
    THE PROBLEM HOW DO I UPDATE 1500 ROWS

    CANT GET IT I HAVE ALLREADY PRODUCT ID

    SHOW YOU EVEN THAT DOSENT WORK ONE FIELD HOW COME

    FAILED! - INSERT INTO products ('products_image','products_image_med','products_image_lrg') VALUES ('1a_s.jpg','1a_s.jpg','1a_s.jpg') WHERE products_id =1805

    ???
     
    Goonline, Oct 4, 2008 IP
  5. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #5
    I am not quite sure I understand the problem, but you do need an UPDATE statement instead of an INSERT.
     
    Social.Network, Oct 4, 2008 IP
  6. Goonline

    Goonline Well-Known Member

    Messages:
    239
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    130
    #6
    Thank you

    I have a table called "products" with 1200 products in it some of the products missing images

    I have all images(file name) by "product id " and i want to insert them into the DB in 3 fields

    1. I need to insert by product id so here comes the WHERE

    WHERE products_id >1806 AND products_id < 2642

    2. I need to insert the same file name into 3 fields in the products table
    ('products_image','products_image_med','products_image_lrg')

    3. And file name
    ('3a_s.jpg','3a_s.jpg','3a_s.jpg'),

    Thank you for the quick response
     
    Goonline, Oct 4, 2008 IP
  7. garrettheel

    garrettheel Peon

    Messages:
    341
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Because you're using the WHERE id =, it would be UPDATE, as previously said, not INSERT. When you say WHERE id =, it's assuming there's already an entry in the database that you're wanting to use, which contradicts the INSERT command you used at the start, which implies you want a new entry.
     
    garrettheel, Oct 4, 2008 IP
  8. Goonline

    Goonline Well-Known Member

    Messages:
    239
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    130
    #8
    Thank you

    So how it all connect

    I did an update success per product when i try the where it failed
     
    Goonline, Oct 4, 2008 IP
  9. garrettheel

    garrettheel Peon

    Messages:
    341
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #9
    are you sure there is an id with that value?
     
    garrettheel, Oct 4, 2008 IP
  10. Goonline

    Goonline Well-Known Member

    Messages:
    239
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    130
    #10
    Yes it is going into the products table

    Each 3images going into one table row

    Now i need to implent the missing image in about 800 products

    means 800 rows that ihave the ID of each one of them and the image name for each field


    Not an easy task
     
    Goonline, Oct 4, 2008 IP