MySQL多表DELETE出错

时间:2015-11-26 08:39:52

标签: php mysql

任何人都可以告诉我以下mysql查询有什么问题?

DELETE FROM table1 as A, table2 as B WHERE A.delivery_status = '3' AND
A.delivered_on < '2015-11-26' AND A.delivery_id = B.delivery_id
  

错误:#1064 - 您的SQL语法出错;检查与您的MySQL服务器版本对应的手册,以便在{<1}}附近的

行附近使用正确的语法

我还尝试as A, table2 as B WHERE A.delivery_status = '3' AND A.delivered_on ',因为< DATE('2015-11-26')delivered_on字段,但没有成功。

3 个答案:

答案 0 :(得分:3)

多表DELETE中的表别名只应在语句的table_references部分声明。在其他地方,允许别名引用但不允许别名声明。您必须输入:

DELETE A,B FROM table1 as A, table2 as B WHERE A.delivery_status = '3' AND
A.delivered_on < '2015-11-26' AND A.delivery_id = B.delivery_id

答案 1 :(得分:0)

试试这个

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
   if (e.Item.ItemType == ListItemType.AlternatingItem || 
       e.Item.ItemType == ListItemType.Item)
    {
       HtmlGenericControl TeklifId = e.Item.FindControl("TeklifId") as HtmlGenericControl;
       string TeklifId = TeklifId.InnerText;  //value here
    }
}

答案 2 :(得分:0)

这对我来说很好用:

DELETE table1 FROM table1 LEFT JOIN table2 ON table1.delivery_id = table2.delivery_id WHEREtable1.delivery_status ='3'AND table2.delivered_on&lt; DATE($ today)AND table1.delivery_id = table2.delivery_id“;