我在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");
我该如何解决?
答案 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
)