hey_dude
hey_dude

Reputation: 9

Error 1064 in mysql

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

Answers (3)

garnertb
garnertb

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

Lightness Races in Orbit
Lightness Races in Orbit

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

AJ.
AJ.

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

Related Questions