SQL常见问题及解决备忘

1.mysql中:you cant't specify tartget table for update in from clause 错误

含义:在同一语句中update或delete某张表的时候,该表不能子查询from的表

eg:错误的sql 
delete from table_name where pid in (     select pid from table_name     group by pid having count(1) > 1 )
eg:修改后的sql
delete from t where pid in (
    select temp.pid from (
        select pid from t 
            group by pid HAVING count(1)>1
    ) temp
)

2.mysql错误:Every derived tabled must have its own alias

含义:每个派生出来的表都需要有一个自己的别名

解决:一般在多表查询的时候,会出现此错误。因为进行嵌套查询的时候子查询出来的结果是作为一个派生表来进行上一级查询的,所以子查询的结果必须要有一个别名。

原文地址:https://www.cnblogs.com/LionheartCGJ/p/7098769.html