Page 1 of 1
insert
Posted: Wed May 31, 2006 6:47 pm
by alexislalas
hello
can i insert into something values somewhat WHERE id = id?
does the WHERE statement works with the insert into statement?
Posted: Wed May 31, 2006 6:55 pm
by bdlang
You don't specify which DMBS you're working with, but yes. This would likely be an UPDATE statement, not an INSERT statement (unless you're working with some sort of subquery, which may be a different case).
Posted: Thu Jun 01, 2006 9:54 am
by alexislalas
im working with mysql.
Posted: Thu Jun 01, 2006 10:08 am
by RobertGonzalez
INSERT queries do not use a WHERE clause unless you are running a subquery...
Code: Select all
INSERT INTO table (`id`, `data`) VALUES (1, (SELECT `data` FROM table2 WHERE id = 5));
Insert by itself won't work with a WHERE because you are in essence adding a row (so how could you compare a new row to something?).
I could be wrong on this.