Reputation: 9
Why does the following show a mysql 1064 error?
I have a the following table:
daily_note (id, time (timestamp), rate_id, note )
On this table I'm executing the following insert:
INSERT INTO daily_note (note)
VALUES ('this is a note')
WHERE rate_id = 37
AND time > '2011-05-22 00:00:00'
Cannot perform insert:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE rate_id = 37 AND time > '2011-05-22 00:' at line 3'
Upvotes: 0
Views: 244
Reputation: 9584
Code should read:
UPDATE DAILY_NOTE
SET field='this is a not'
WHERE rate_id = 37
AND time > '2011-05-22 00:00:00'
Upvotes: 1
Reputation: 385144
INSERT
with WHERE
makes no sense.
INSERT
creates new rows, whereas WHERE
specifies criteria for retrieving/updating existing rows.
Read up about the syntax and meaning of the statement that you're trying to use, before trying to use it.
Upvotes: 1
Reputation: 28174
You can't INSERT using a WHERE statement. If you want to modify existing records based on some condition/criteria, use an UPDATE statement instead of INSERT.
Upvotes: 1