Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. sqlite> select * from lookup;
  2. node|id
  3. 1|1
  4. 1|2
  5. 2|4
  6. 2|6
  7. sqlite> select * from tag;
  8. tagid|data
  9. 1|bar
  10. 2|baz
  11. 3|geek
  12. 4|foo
  13. 5|bank
  14. 6|auto
  15.  
  16. select id from tag where not exists (select tagid from lookup);
  17. # I am expecting the following result: 3, 5
  18.  
  19. select
  20. id
  21. from
  22. tag t
  23. where
  24. not exists (
  25. select
  26. 'x'
  27. from
  28. lookup l
  29. where
  30. l.tagid = t.id -- correlation
  31. );
  32.  
  33. select
  34. t.id
  35. from
  36. tag t
  37. left outer join
  38. lookup l
  39. on t.id = l.tagid
  40. where
  41. l.tagid is null;
  42.  
  43. delete from
  44. tag
  45. where
  46. not exists (
  47. select
  48. 'x'
  49. from
  50. lookup l
  51. where
  52. l.tagid = tag.id
  53. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement