Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

INSERT statement in MySQL

Options
  • 20-04-2005 12:58pm
    #1
    Registered Users Posts: 78 ✭✭


    Hi, i've been at this SQL problem for ages and i cannot find a solution yet it seems like an extremely trivial problem. I have a database with three columns in it Name, Price and Count. I am trying to insert a value to the count column where name = 'some value'. I have tried so many different ways of doing this but i keep on getting a 'check SQL Syntax error'. I can do it using referencing when i break the table up into two tables with Name, Price and Name Count as the columns but i need to keep it as one table. Does anybody have any ideas? I've been trying many variations of:

    INSERT into tablename(count)
    VALUES('12')
    WHERE Name = 'some value';


Comments

  • Registered Users Posts: 190 ✭✭pan


    for one, remove the ";" from the end of the statement and try it.
    Also make sure if your are inserting integer values, that the corresponding table in the database also stores the data as integers i.e. if stored as strings then you would get an error.

    pan


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    That should be an UPDATE statement.

    INSERT is for adding rows. You can't add a row WHERE some matching criteria is satisfied :)

    You UPDATE a row WHERE some matchnig criteria is satisfied.


  • Registered Users Posts: 3,012 ✭✭✭BizzyC


    bonkey wrote:
    That should be an UPDATE statement.

    INSERT is for adding rows. You can't add a row WHERE some matching criteria is satisfied :)

    You UPDATE a row WHERE some matchnig criteria is satisfied.
    Hit the nail on the head.


  • Registered Users Posts: 2,781 ✭✭✭amen


    you should avoid using SQL keywords such as Count for column names instead why use something like ProductCount or NumItems etc


  • Registered Users Posts: 78 ✭✭al.


    Cheers Bonkey that was driving me nuts, thanks for the advice amen ill use sonething other than count


  • Advertisement
Advertisement