Syntax error on update SQL statement - mysql

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];

Related

How to update table set column = null where column = '\' without error of MySQL server version for the right syntax to use near ''\'' at line 1

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 = '\\'

MySQL triggers on the same table

I have some tables. If I update st_income column, then I want to update total_income column, and when I do this I want update next column (income_per_person). I tried this:
IF (NEW.st_income <> OLD.st_income) THEN
SET NEW.total_income=OLD.total_income + (NEW.st_income-OLD.st_income);
END IF
IF(NEW.total_income <> OLD.total_income) THEN
SET NEW.income_per_person=NEW.total_income/(family_mem_numbers+1)/12;
END IF
but it doesn't work.
EDIT
This is return message:
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 'IF(NEW.total_income <> OLD.total_income) THEN SET NEW.income_per_person=NEW' at line

ODBC Error:You have an error in your SQL syntax;

I try to update a table, with the value of OPC SIMULATIE:Configured Aliases.PLC1.RPM
But then i get this:
Executing ODBC update: update test set where test = OPC SIMULATIE:Configured Aliases.PLC1.RPM
ODBC Error: [[[MySQL][ODBC 3.51 Driver][mysqld-5.6.11]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 `test` = 'OPC SIMULATIE:Configured Aliases.PLC1.RPM'' at line 1 42000 1064]]
on: Could not ExecDirect: update test set where `test` = 'OPC SIMULATIE:Configured Aliases.PLC1.RPM'
ODBC Error: [[[MySQL][ODBC 3.51 Driver][mysqld-5.6.11]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 `test` = 'OPC SIMULATIE:Configured Aliases.PLC1.RPM'' at line 1 42000 1064]]
on: update test set where `test` = 'OPC SIMULATIE:Configured Aliases.PLC1.RPM'
Can someone please help?
You haven't specified what fields to update:
update test set where test = 'OPC SIMULATIE:Configured Aliases.PLC1.RPM'
should have something like:
update test set field='value' where test = 'OPC SIMULATIE:Configured Aliases.PLC1.RPM'

Conditional update/insert in MySQL

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.

Error in my stored-procedure

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.