insert

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
alexislalas
Forum Commoner
Posts: 44
Joined: Sun Feb 19, 2006 10:09 pm

insert

Post by alexislalas »

hello


can i insert into something values somewhat WHERE id = id?


does the WHERE statement works with the insert into statement?
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post 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).
alexislalas
Forum Commoner
Posts: 44
Joined: Sun Feb 19, 2006 10:09 pm

Post by alexislalas »

im working with mysql.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply