Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding into an existing row

    I use this command:
    Code:
    insert into orders (foobar) values ('a') where id = "1";
    I now have a table called "orders" with a row called "foobar". Its id is "1" and the row "foobar" where id equals "1" is "a".

    What I am wanting to do is add into the existing row, so that "a" becomes "ab".
    Is it possible to add into an existing row, rather than overwrite it?
    Last edited by kaidine; 11-22-2011 at 12:27 PM.

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,979
    Thanks
    120
    Thanked 76 Times in 76 Posts
    Row cant have name (foobar).
    You can update single column in a row. That would be what you want.

    Code:
    update orders set foobar = 'a' where id = 1
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    Quote Originally Posted by kaidine View Post
    I use this command:
    Code:
    insert into orders (foobar) values ('a') where id = "1";
    No, you don't. That is invalid SQL. You can't use a WHERE clause with INSERT.

    I would *assume* you meant that you did
    Code:
    INSERT INTO orders ( id, foobar ) VALUES ( 1, 'a' )
    And then, to add on to foobar, you would do
    Code:
    UPDATE orders SET foobar = CONCAT(foobar,'b') WHERE id = 1
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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