How to update table set column = null where column = \ in mysql?
I always got error of 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 ''\'' at line 1
You should use '\\'
update students set firstname = null where firstname = '\\'
I'm getting a syntax error when I want to use md5 over url column. Not sure what's wrong with it:
update table {$GLOBALS['tables']['tableame']} set urlhash = md5(url)
Error message:
Database error 1064 while doing query 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 'table tablename set urlhash = md5(url)' at line 1
Try passing md5 in single quotes as that is a string
update {$GLOBALS['tables']['tableame']} set urlhash = 'MD5_URL_HERE'
following is the syntax
UPDATE table_name SET column_name = `new_value' [WHERE condition];
I'm trying to add a trigger to my database however I get an "not meaningful" syntax error from mysql.
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 '' at line 5
CREATE TRIGGER update_balance_table AFTER INSERT ON _explorer.transfers
FOR EACH ROW
BEGIN
/* TO*/
INSERT INTO _explorer.balances (account, balance) VALUES (new.account, new._to) ON DUPLICATE KEY UPDATE balance = balance + new._quantity;
/* FROM*/
UPDATE _explorer.balances SET balance = balance - new._quantity WHERE account = new._from;
END
I found here a topic about an MySQL IF, ELSE query,i adapted it but i can't figure it out what is the problem with it.
Here is the query:
IF (SELECT * FROM `jos_import03_07_2011` WHERE `cod_oem` = 'OP-4CL') IS NULL THEN
INSERT INTO `jos_import03_07_2011` (`tip_imp`, `tip_produs`, `producator`,
`cod_intern`, `desc`, `cod_oem`, `pret`, `valuta`) VALUES ('Imprimanta Laser',
'Piese Schimb', 'BROTHER', 'BR-200503', '', 'OP-4CL', '338.49', 'EUR');
ELSE UPDATE `jos_import03_07_2011` SET `pret` = '338.49' WHERE `cod_oem` = 'OP-4CL';
END IF;
And here is the error:
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 'IF (SELECT * FROM
`jos_import03_07_2011` WHERE `cod_oem` = 'OP-4CL') IS NULL THE' at line 1
This is the original post:
Conditional mySQL statement. If true UPDATE, if false INSERT
Thanks,
Sebastian
UPDATE
Error code for IF EXISTS:
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 'IF EXISTS (SELECT * FROM
`jos_import03_07_2011` WHERE `cod_oem` = 'OP-4CL') THEN' at line 1
Any reason you can't use the INSERT ... ON DUPLICATE KEY syntax?
INSERT INTO `jos_import03_07_2011` (`tip_imp`, `tip_produs`, `producator`,
`cod_intern`, `desc`, `cod_oem`, `pret`, `valuta`)
VALUES ('Imprimanta Laser', Piese Schimb', 'BROTHER', 'BR-200503', '', 'OP-4CL', '338.49', 'EUR')
ON DUPLICATE KEY UPDATE SET pret = VALUES(pret)
would be far more efficient: one less query and far less code to debug.
i have an error in my stored-procedure. I use MySql DB
SET #counter = 1;
SET #last = 0;
UPDATE Customer SET ordre = (IF(#last = customer_id,#counter + 1,#counter = 1)),
#last = customer_id
My Error
Script line: 3 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 '#last = customer_id ORDER BY
customer_id' at line 2
You cannot set variables in SET clause of UPDATE statement. '#last = customer_id' causes the error.
From the reference -
UPDATE syntax - '...SET col_name1=expr1 [, col_name2=expr2 ...]'
The SET clause indicates which columns to modify and the values they should be given.