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)
Related
I have the following query :
update event
set event.Paid = payment.amount
from event, payment
where payment.event_id = event.eid
The above query gives following 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 event, payment where payment.event_id = event.eid' at line
3
You join clause is wrong anyway
You should not use the implicit join syntax based on comma separated table name and where
you should use explicit join syntax (for mysql)
update event
INNER JOIN payment ON payment.event_id = event.eid
set event.Paid = payment.amount
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
SELECT core_student.STUDENT_ID, core_student.FIRST_NAME, core_student.LAST_NAME
FROM `core_student`
INNER_JOIN `ssp_student`
WHERE ssp_student.STUDENT_ID = core_student.STUDENT_ID;
throws an error on the WHERE clause:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to user near 'ssp_student' WHERE ssp_student.STUDENT_ID = core_student.STUDENT_ID
I just want to select the fields listed in the SELECT, then join all columns from ssp_student where the ssp_student.STUDENT_ID field is the same as the core_student.STUDENT_ID field.
Correct way is
SELECT core_student.STUDENT_ID, core_student.FIRST_NAME, core_student.LAST_NAME
FROM `core_student`
INNER JOIN `ssp_student`
on ssp_student.STUDENT_ID = core_student.STUDENT_ID;
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'
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