带子查询的SqLite Delete命令

时间:2011-08-24 11:15:18

标签: sqlite subquery sql-delete

我有以下查询:

SELECT * FROM (
    SELECT * FROM pojmovi WHERE pojam LIKE '%og'
) WHERE pojam NOT LIKE '%olog';

这可以按预期工作,从列pojmovi中选择以'og'结尾但不在'olog'中的所有内容,现在,我想删除这些结果,所以我尝试的是:

DELETE FROM (
    SELECT * FROM pojmovi WHERE pojam LIKE '%og'
) WHERE pojam NOT LIKE '%olog';

此查询会导致接近“(”:语法错误) 这在sqlite中是否可行?

2 个答案:

答案 0 :(得分:2)

这可能无法正常工作 - 您尝试从中间查询结果中删除,这是没有意义的,也是不允许的。您需要在DELETE FROM之后指定一个实际的表。像这样:

 DELETE FROM pojmovi WHERE ( pojam LIKE '%og' ) AND (pojam NOT LIKE '%olog' );

答案 1 :(得分:0)

怎么样

SELECT * FROM pojmovi WHERE pojam LIKE '%og' and pojam NOT LIKE '%olog';

DELETE FROM pojmovi WHERE pojam LIKE '%og' and pojam NOT LIKE '%olog';  

您的查询会很慢,因为他们无法使用索引(因为您正在做“LI ...”)