Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sqlite> select * from lookup;
- node|id
- 1|1
- 1|2
- 2|4
- 2|6
- sqlite> select * from tag;
- tagid|data
- 1|bar
- 2|baz
- 3|geek
- 4|foo
- 5|bank
- 6|auto
- select id from tag where not exists (select tagid from lookup);
- # I am expecting the following result: 3, 5
- select
- id
- from
- tag t
- where
- not exists (
- select
- 'x'
- from
- lookup l
- where
- l.tagid = t.id -- correlation
- );
- select
- t.id
- from
- tag t
- left outer join
- lookup l
- on t.id = l.tagid
- where
- l.tagid is null;
- delete from
- tag
- where
- not exists (
- select
- 'x'
- from
- lookup l
- where
- l.tagid = tag.id
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement