Reputation: 1569
I tried running this sql
UPDATE table
SET read = 1
WHERE col1_id = 2
AND col3_id = 1;
and it return an error (error in your sql syntax)
#1064 - 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 'read = 1 WHERE team_notification_id = 2 AND listener_id = 1' at line 1
But when I used thesame WHERE and AND :), in a SELECT statement no error was returned.
SELECT *
FROM read
WHERE col1_id = 2
AND col3_id = 1
please what did I do wrong, I am no seeing it.
Upvotes: 2
Views: 1967
Reputation: 1346
After keyword UPDATE there should be a table name. If your table has actually name table
(that's a bit strange) you should escape it to let MySQL know it's not a keyword "table" but actual table name.
The same thing is about read
.
Both table
and read
are MySQL keywords (the full list is here http://dev.mysql.com/doc/refman/5.7/en/keywords.html) so if it's your actual table and column names then you should escape it.
Better to escape all table and column names to prevent issues like that.
Escaping in MySQL is done with backtick symbol ` so your query will looks like:
UPDATE `table`
SET `read` = 1
WHERE `col1_id` = 2
AND `col3_id` = 1;
Upvotes: 3
Reputation: 1635
UPDATE tablename
SET `field_name` = 1
WHERE col1_id = 2
AND col3_id = 1;
Upvotes: 1