从LIMIT 1错误删除

时间:2013-12-30 17:45:03

标签: android mysql sql sqlite

我在SQLite中有LIMIT 1的问题,我的查询没有LIMIT 1工作正常,但有时删除每个重复的元素。我想删除1行。

这有效:

myDataBase.execSQL("DELETE FROM praca
 WHERE pomieszczenie_id="+pomieszczenieid+" 

AND (praca.usluga_id IN (SELECT usluga_id FROM usluga
     WHERE usluga_nazwa='"+childvalue+"'))
AND (sciana_id IN(SELECT sciana_id from sciana 
    WHERE sciana_nazwa='"+rodzic_nazwa+"'))");  

返回“LIMIT”语法错误

myDataBase.execSQL("DELETE FROM praca
 WHERE pomieszczenie_id="+pomieszczenieid+" 

AND (praca.usluga_id IN (SELECT usluga_id FROM usluga
     WHERE usluga_nazwa='"+childvalue+"'))
AND (sciana_id IN(SELECT sciana_id from sciana 
    WHERE sciana_nazwa='"+rodzic_nazwa+"')) LIMIT 1");  

我该如何解决?

3 个答案:

答案 0 :(得分:4)

您可能需要启用SQLITE ENABLE UPDATE DELETE LIMIT或类似THIS的解决方法:

 delete from tablename where rowid in (
    select rowid from tablename condition LIMIT 1)

以上查询只是一个示例,请将其替换为您的查询和条件。

答案 1 :(得分:1)

我认为你应该启用 SQLITE_ENABLE_UPDATE_DELETE_LIMIT http://www.sqlite.org/compile.html#enable_update_delete_limit

您必须使用NDK编译SQLite,并添加参数以启用SQLITE_ENABLE_UPDATE_DELETE_LIMIT

答案 2 :(得分:0)

请尝试这样:

DELETE FROM praca where pomieszczenie_id in
(
select pomieszczenie_id from praca
 WHERE pomieszczenie_id="+pomieszczenieid+" 

AND (praca.usluga_id IN (SELECT usluga_id FROM usluga
     WHERE usluga_nazwa='"+childvalue+"'))
AND (sciana_id IN(SELECT sciana_id from sciana 
    WHERE sciana_nazwa='"+rodzic_nazwa+"')) LIMIT 1
)