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'
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.
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.
Code should read:
UPDATE DAILY_NOTE
SET field='this is a not'
WHERE rate_id = 37
AND time > '2011-05-22 00:00:00'
精彩评论