删除id id最小的帖子

时间:2017-03-16 11:02:36

标签: mysql sql select

Delete from post 
where id_post 
in 
( 
    select MIN(id_post)
    from post
    where id_owner='2'
)

返回: “您无法在FROM子句”

中为更新指定目标表'post'

我做错了什么?

2 个答案:

答案 0 :(得分:3)

问题是MySQL,如果你在表上执行UPDATE / INSERT / DELETE,则不能在内部查询中引用该表(但是你可以从该外表中引用一个字段......)

解决方法是用子查询替换post的实例(select MIN(id_post)     从帖子     其中id_owner ='2'),像这样

Delete from post 
where id_post 
in 
( 
    select id_post 
    from (select MIN(id_post)
    from post
    where id_owner='2') as A
)

答案 1 :(得分:0)

如何使用wb.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _ ws.Name & "!" & ws.Range("A1").CurrentRegion.Address(ReferenceStyle:=xlR1C1), Version:=6).CreatePivotTable _ TableDestination:=ws2.Range("A1"), TableName:="PivotTable10", DefaultVersion _ :=6 ORDER BY

LIMIT

注意:不要在数字常量周围使用单引号。我猜Delete p from post p where id_owner = 2 order by id_post limit 1; 是数字。