mysql delete syntax error - mysql

I'm trying to delete multiple rows from multiple tables having the same condition but will always return syntax error.
This is the code:
DELETE FROM table1,table2,table3
WHERE guid = 'CE4EF453-937F-C7F9-7AE429VB0128'
The error code is:
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 'WHERE guid = 'CE4EF453-937F-C7F9-7AE429VB0128'' at line 2

You are missing INNER JOINs. Something like the following perhaps.
DELETE FROM table1,table2,table3
USING table1 INNER JOIN table2 INNER JOIN table3
WHERE table1.guid = 'CE4EF453-937F-C7F9-7AE429VB0128'
AND table2.guid = table1.guid
AND table3.guid = table1.guid
(Reference)

Give this one a shot:
DELETE FROM table1,table2,table3
WHERE table1.guid = 'CE4EF453-937F-C7F9-7AE429VB0128'
AND table1.guid = table2.guid
AND table1.guid = table3.guid

Related

Syntax error while trying to run a update query in mysql

While trying to execute the query given below, I get an syntax error
I need to update a column value from table civicrm_address and move it from abc_abc_drupal_civi_4_17 database to abc_drupal database
In order to achieve it, I get an syntax error near from FROM,
The error I get is as follows
#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 'FROM abc_abc_drupal_civi_4_17.civicrm_address,abc_drupal.civic' at line 3
How can I fix it?
UPDATE abc_drupal.civicrm_address
SET abc_drupal.civicrm_address.state_province_id = abc_abc_drupal_civi_4_17.civicrm_address.state_province_id
FROM abc_abc_drupal_civi_4_17.civicrm_address,abc_drupal.civicrm_address
WHERE abc_drupal.civicrm_address.state_province_id IS NULL
AND abc_abc_drupal_civi_4_17.civicrm_address.state_province_id IS NOT NULL
AND abc_abc_drupal_civi_4_17.civicrm_address.id = abc_drupal.civicrm_address.id
AND abc_abc_drupal_civi_4_17.civicrm_address.contact_id IS NOT NULL;
MySQL puts JOIN in the UPDATE clause, not through a separate FROM (the FROM is used by SQL Server and Postgres).
Your query as written is hard to decipher. I would strongly recommend that you use table aliases, so the query is more easily written and read:
UPDATE abc_drupal.civicrm_address a JOIN
abc_abc_drupal_civi_4_17.civicrm_address aa
ON aa.id = a.id
SET a.state_province_id = aa.state_province_id
WHERE a.state_province_id IS NULL
aa.state_province_id IS NOT NULL AND
aa.contact_id IS NOT NULL;
You need to specify set later like below:
UPDATE TABLEA a
JOIN TABLEB b ON a.join_colA = b.join_colB
SET a.columnToUpdate = [something]
UPDATE abc_drupal.civicrm_address
join abc_abc_drupal_civi_4_17.civicrm_address inner join abc_drupal.civicrm_address
on abc_abc_drupal_civi_4_17.civicrm_address.id = abc_drupal.civicrm_address.id
SET abc_drupal.civicrm_address.state_province_id = abc_abc_drupal_civi_4_17.civicrm_address.state_province_id
where abc_drupal.civicrm_address.state_province_id IS NULL
AND abc_abc_drupal_civi_4_17.civicrm_address.state_province_id IS NOT NULL
AND abc_abc_drupal_civi_4_17.civicrm_address.contact_id IS NOT NULL

UPDATE USING PHPMYADMIN

Good Afternoon,
I am trying to update a table using price data from another table however I get an error using an inner join. I am sure its something very stupid but having spent the best part of my day on this its time to ask for help.
If I do the following SELECT statement to test my inner join syntax works as it should
SELECT *
FROM polaracc_osrs_property_field_value
INNER JOIN polaracc_osrs_properties
ON polaracc_osrs_property_field_value.pro_id = polaracc_osrs_properties.id
WHERE polaracc_osrs_property_field_value.field_id =112
However when I then try and run an update statement using the price from one table to populate the 2nd I get the below error
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 'FROM polaracc_osrs_property_field_value INNER JOIN
polaracc_osrs_properties ' at line 3
The syntax used for the update statement is below
UPDATE polaracc_osrs_property_field_value
SET polaracc_osrs_property_field_value.value_integer = polaracc_osrs_properties.price
FROM polaracc_osrs_property_field_value
INNER JOIN polaracc_osrs_properties
ON polaracc_osrs_property_field_value.pro_id = polaracc_osrs_properties.id
WHERE polaracc_osrs_property_field_value.field_id = 112
Your join needs to happen before you set your values like this:
UPDATE polaracc_osrs_property_field_value
INNER JOIN polaracc_osrs_properties
ON polaracc_osrs_property_field_value.pro_id = polaracc_osrs_properties.id
SET polaracc_osrs_property_field_value.value_integer = polaracc_osrs_properties.price
WHERE polaracc_osrs_property_field_value.field_id = 112;
Hope this helps.

Syntax error in mySQL Update-Query

I try to execute the query but get an error. This is my query:
UPDATE
prepares_for_exam
SET
prepares_for_exam.exam_id = product.id
FROM
prepares_for_exam,
product
WHERE
prepares_for_exam.id = product.prepares_for_exam_id
and I get 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 'FROM prepares_for_exam, product WHERE prepares_for_exam.id = product.prepares_fo' at line 1
I did the Update Query 100-times with an FROM clause and never had problems... Whats my fault?!?
You are using the SQL-Server syntax. In MySQL it is a little bit different.
UPDATE
prepares_for_exam
JOIN
product
ON
prepares_for_exam.id = product.prepares_for_exam_id
SET
prepares_for_exam.exam_id = product.id
UPDATE
prepares_for_exam
SET
prepares_for_exam.exam_id = (select product.id FROM
prepares_for_exam JOIN product on prepares_for_exam.id = product.prepares_for_exam_id)

syntax error in update with inner join query mysql

My Query :
UPDATE i SET i.CurStock = i.CurStock-g.Qty
FROM inv_inventarymaster AS i INNER JOIN inv_goodsissue AS g
ON i.ItemName = g.ItemName WHERE g.DATE='2014-03-20';
Error:
You have an error in your SQL syntax; check the manual that correspond
to your MySQL server version for the right syntax to use near 'FROM
inv_inventarymaster as i INNER JOIN inv_goodsissue as g ON ' at line 1
Kindly help me getting the right syntax.
Try this ...Not Tested but as MYsql http://dev.mysql.com/doc/refman/5.0/en/update.html
UPDATE inv_inventarymaster AS i INNER JOIN inv_goodsissue AS g SET
i.CurStock = i.CurStock-g.Qty
WHERE i.ItemName = g.ItemName and g.DATE='2014-03-20';
its not a right thing to use FROM in Mysql UPDATE query.
You can use the query like this
UPDATE inv_inventarymaster AS i
INNER JOIN inv_goodsissue AS g ON i.ItemName = g.ItemName
SET i.CurStock = i.CurStock-g.Qty
WHERE g.DATE='2014-03-20';

select info from dbs and delete (not working)

I have this query:
DELETE FROM amx_admins_servers, amx_amxadmins
WHERE
amx_admins_servers.admin_id = (SELECT id FROM amx_amxadmins WHERE username='kokoz')
AND amx_amxadmins.username = 'kokoz'
but didnt work.
I get sql error:
#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 'WHERE amx_admins_servers.admin_id = (SELECT id FROM
amx_amxadmins WHERE username' at line 2
where is the problem ?
Looks like you want to delete an admin user and all its entries in the server table. Use
DELETE a, s
FROM amx_amxadmins a
inner join amx_admins_servers s on a.id = s.admin_id
WHERE a.username='kokoz'