select info from dbs and delete (not working) - mysql

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'

Related

Getting syntax error using WITH (Common Table Expressions) in mysql 8

I am using mysql 8.0.21. I am trying to execute this statement:
WITH t
AS (SELECT h.store_hsh,
Avg(s.sales) AS SALES_AVG,
Avg(s.customers) AS CSTMR_AVG
FROM sat_day_facts s
INNER JOIN link_day l
ON s.link_day_hsh = l.link_day_hsh
INNER JOIN hub_store h
ON h.store_hsh = l.store_hsh
GROUP BY h.store_hsh)
SELECT t.store_hsh,
Now() AS LOAD_DATETIME,
Now() AS LOAD_END_DATETIME,
t.sales_avg,
t.cstmr_avg,
(SELECT 1 + Count(*)
FROM t t1
WHERE t1.sales_avg > t.sales_avg) AS SALES_RANK;
but I keep having this error
ProgrammingError: 1064 (42000): 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 'WITH t as (select h.STORE_HSH, AVG(s.SALES) as SALES_AVG , AVG(s.CUSTOMERS) as' at line 1
I checked the manual of SQL but still don't understand what is going wrong.
Does anyone could help?

Syntax error in sql query of copying data from one table to another

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

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)

What is wrong with this MySQL query? right syntax for INNER_JOIN WHERE clause?

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;

mysql delete syntax error

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