...

View Full Version : Adding into an existing row



kaidine
11-22-2011, 12:24 PM
I use this command:

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?

BubikolRamios
11-22-2011, 02:40 PM
Row cant have name (foobar).
You can update single column in a row. That would be what you want.



update orders set foobar = 'a' where id = 1

Old Pedant
11-22-2011, 08:28 PM
I use this command:

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


INSERT INTO orders ( id, foobar ) VALUES ( 1, 'a' )

And then, to add on to foobar, you would do


UPDATE orders SET foobar = CONCAT(foobar,'b') WHERE id = 1



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum