This article mainly introduces the MySQL you can’t specify target table for update in from clause error resolution, need friends can refer to
The error of you can’t specify target table for update in from clause in MySQL means that you can’t select some values in the same table and then update the table (in the same statement). For example, the following SQL:
delete from tbl where id in
(
select max(id) from tbl a where EXISTS
(
select 1 from tbl b where a.tac=b.tac group by tac HAVING count(1)&>1
)
group by tac
)
Just rewrite it as follows:
delete from tbl where id in
(
select a.id from
(
select max(id) id from tbl a where EXISTS
(
select 1 from tbl b where a.tac=b.tac group by tac HAVING count(1)&>1
)
group by tac
) a
)
That is to say, select the result through the middle table again, so as to avoid the error. Note that this problem only occurs in mysql, and will not occur in MSSQL and Oracle.
Similar Posts:
- [Solved] MYSQL Error: You can’t specify target table for update in FROM clause
- [Solved] MySQL Error Code: 1093. You can’t specify target table ‘car’ for update in …
- Hive SemanticException:Expression not in GROUP BY
- [Solved] MYSQL ERROR 1093 – You can’t specify target table ‘readbook’ for update in FROM clause
- [Solved] SELECT list is not in GROUP BY clause and contains nonaggregated
- [Solved] sql Error: You can’t specify target table ‘tb_cr_circulate_gtsc’ for update in FROM clause
- [Solved] MYSQL Error: “ Every derived table must have its own alias”
- Mysql Error: 1140 – In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated column ‘a.store’; this is incompatible with sql_mode=only_full_group_by
- 12 Methods of SQL Error Injection [How to Inject]
- [Solved] must appear in the GROUP BY clause or be used in an aggregate function