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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

INSERT statement in MySQL

  • 20-04-2005 11:58am
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 78 ✭✭al.


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


  • Advertisement
Advertisement