0

I have following query:

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

This works as expected, selecting all from column pojmovi that ends in 'og' but not in 'olog', now, I want to delete those results, so I'm trying something like:

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

And this query causes near "(": syntax error Is this somehow possible in sqlite?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
realitylord
  • 23
  • 1
  • 8

2 Answers2

2

This can't possibly work as you want - you attempt to delete from an intermediate query result and that makes no sense and is not allowed. You need to specify an actual table after DELETE FROM. Something like this:

 DELETE FROM pojmovi WHERE ( pojam LIKE '%og' ) AND (pojam NOT LIKE '%olog' );
sharptooth
  • 167,383
  • 100
  • 513
  • 979
  • Thanks for your help and time. After little experimenting, I came up with this query that works as expected, as far as I can tell: `DELETE FROM pojmovi WHERE id IN ( SELECT id FROM ( SELECT * FROM pojmovi WHERE pojam LIKE '%og' ) WHERE pojam NOT LIKE '%olog' )` – realitylord Aug 24 '11 at 11:45
0

How about

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

and

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

Your queries will be slow because they cannot use an index (because you are doing LIKE "%...")

cristian
  • 8,676
  • 3
  • 38
  • 44