mysql-error-1093

Delete - I can't specify target table?

╄→гoц情女王★ 提交于 2019-11-28 19:10:47
Why this query doesn't work? DELETE FROM recent_edits WHERE trackid NOT IN (SELECT DISTINCT history.trackid FROM history JOIN recent_edits ON history.trackid=recent_edits.trackid GROUP BY recent_edits.trackid) I get this message : "You can't specify target table "recent_edits" for update in FROM clause Try in this way DELETE FROM recent_edits WHERE trackid NOT IN (select * from (SELECT DISTINCT history.trackid FROM history JOIN recent_edits ON history.trackid=recent_edits.trackid GROUP BY recent_edits.trackid) as t); You can't post-process a table which is locked for deletion. using the hack

MySQL: You can't specify target table 'tasks' for update in FROM clause

送分小仙女□ 提交于 2019-11-28 04:49:34
问题 I have got MySQL error "You can't specify target table 'tasks' for update in FROM clause" running the following query: DELETE FROM tasks WHERE tasks.id IN ( SELECT tasks.id FROM tasks JOIN deadlines ON deadlines.id = deadline_id WHERE DATE_ADD(tasks.created_at, INTERVAL deadlines.duration DAY) <= NOW() ) How can I manage this? Thanx! 回答1: You can wrap it in a subquery like so. The issue is that MySQL can't update rows that it's also querying. This will make MySQL use a temporary table

Deleting a row based on the max value

感情迁移 提交于 2019-11-27 15:37:58
How can I structure a mySQL query to delete a row based on the max value. I tried WHERE jobPositonId = max(jobPostionId) but got an error? Use: DELETE FROM TABLE t1 JOIN (SELECT MAX(jobPositonId) AS max_id FROM TABLE) t2 WHERE t1.jobPositonId = t2.max_id Mind that all the rows with that jobPositonId value will be removed, if there are duplicates. The stupid part about the 1093 error is that you can get around it by placing a subquery between the self reference: DELETE FROM TABLE WHERE jobPositonId = (SELECT x.id FROM (SELECT MAX(t.jobPostionId) AS id FROM TABLE t) x) Explanation MySQL is only

SQL UPDATE with sub-query that references the same table in MySQL

浪子不回头ぞ 提交于 2019-11-27 13:02:37
I'm trying to update a column's value in a bunch of rows in a table using UPDATE. The problem is that I need to use a sub-query to derive the value for this column, and it depends on the same table. Here's the query: UPDATE user_account student SET student.student_education_facility_id = ( SELECT teacher.education_facility_id FROM user_account teacher WHERE teacher.user_account_id = student.teacher_id AND teacher.user_type = 'ROLE_TEACHER' ) WHERE student.user_type = 'ROLE_STUDENT'; Ordinarily if teacher and student were in 2 different tables, mysql wouldn't complain. But since they are both

Delete - I can't specify target table?

痞子三分冷 提交于 2019-11-27 12:20:20
问题 Why this query doesn't work? DELETE FROM recent_edits WHERE trackid NOT IN (SELECT DISTINCT history.trackid FROM history JOIN recent_edits ON history.trackid=recent_edits.trackid GROUP BY recent_edits.trackid) I get this message : "You can't specify target table "recent_edits" for update in FROM clause 回答1: Try in this way DELETE FROM recent_edits WHERE trackid NOT IN (select * from (SELECT DISTINCT history.trackid FROM history JOIN recent_edits ON history.trackid=recent_edits.trackid GROUP

SQL DELETE with JOIN another table for WHERE condition

人盡茶涼 提交于 2019-11-27 03:57:17
问题 I have to delete rows from guide_category that have no relation with guide table (dead relations). Here is what I want to do, but it of course does not work. DELETE FROM guide_category AS pgc WHERE pgc.id_guide_category IN (SELECT id_guide_category FROM guide_category AS gc LEFT JOIN guide AS g ON g.id_guide = gc.id_guide WHERE g.title IS NULL) Error: You can't specify target table 'guide_category' for update in FROM clause 回答1: Due to the locking implementation issues, MySQL does not allow

MySQL Getting around error 1093

百般思念 提交于 2019-11-26 23:38:36
问题 Error 1093 states that you can't UPDATE or DELETE using a subquery if your subquery queries the table you are deleting from. So you can't do delete from table1 where id in (select something from table1 where condition) ; Ok, what's the best way to work around that restriction, (assuming you really do need to subquery to perform the delete and cannot eliminate the self referencing subquery entirely?) Edit: Here's the query for those who are interested: mysql> desc adjacencies ; +---------+----

SQL DELETE with JOIN another table for WHERE condition

▼魔方 西西 提交于 2019-11-26 20:28:14
I have to delete rows from guide_category that have no relation with guide table (dead relations). Here is what I want to do, but it of course does not work. DELETE FROM guide_category AS pgc WHERE pgc.id_guide_category IN (SELECT id_guide_category FROM guide_category AS gc LEFT JOIN guide AS g ON g.id_guide = gc.id_guide WHERE g.title IS NULL) Error: You can't specify target table 'guide_category' for update in FROM clause Due to the locking implementation issues, MySQL does not allow referencing the affected table with DELETE or UPDATE . You need to make a JOIN here instead: DELETE gc.* FROM

SQL UPDATE with sub-query that references the same table in MySQL

只愿长相守 提交于 2019-11-26 18:14:44
问题 I'm trying to update a column's value in a bunch of rows in a table using UPDATE. The problem is that I need to use a sub-query to derive the value for this column, and it depends on the same table. Here's the query: UPDATE user_account student SET student.student_education_facility_id = ( SELECT teacher.education_facility_id FROM user_account teacher WHERE teacher.user_account_id = student.teacher_id AND teacher.user_type = 'ROLE_TEACHER' ) WHERE student.user_type = 'ROLE_STUDENT';

how to delete duplicate rows from a table in mysql

一个人想着一个人 提交于 2019-11-26 09:13:59
问题 I need to delete duplicate record from table in mysql. So i have a table name \"employee\" fields are empid, empname, empssn for getting duplicate record i have written a query SELECT COUNT(empssn), empssn FROM employee GROUP BY empssn HAVING COUNT(empssn)>1 Now i want to delete duplicate records. for that i have written query is. DELETE FROM employee WHERE (empid, empssn) NOT IN (SELECT MIN(empid), empssn FROM employee GROUP BY empssn); you can assume records in table are EmpId EmpName