Guest User

Untitled

a guest
May 27th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. DROP TABLE IF EXISTS appointments;
  2. CREATE TABLE appointments (
  3. id integer,
  4. title varchar(255),
  5. created_at date
  6. );
  7.  
  8. DROP TABLE IF EXISTS appointment_dates;
  9. CREATE TABLE appointment_dates (
  10. id integer,
  11. appointment_id integer,
  12. confirmed boolean
  13. );
  14.  
  15. INSERT INTO appointments VALUES (1, 'one', '2018-05-21');
  16. INSERT INTO appointment_dates VALUES (1, 1, false);
  17. INSERT INTO appointment_dates VALUES (2, 1, true);
  18.  
  19. INSERT INTO appointments VALUES (2, 'two', '2018-05-21');
  20. INSERT INTO appointment_dates VALUES (3, 2, false);
  21. INSERT INTO appointment_dates VALUES (4, 2, false);
  22.  
  23. INSERT INTO appointments VALUES (3, 'three', '2018-05-22');
  24. INSERT INTO appointment_dates VALUES (4, 3, false);
  25. INSERT INTO appointment_dates VALUES (5, 3, false);
  26.  
  27. INSERT INTO appointments VALUES (4, 'four', '2018-05-21');
  28.  
  29. SELECT *
  30. FROM appointments a
  31. LEFT JOIN appointment_dates ad
  32. ON a.id = ad.appointment_id
  33. AND ad.confirmed = true
  34. WHERE a.created_at = '2018-05-21'
  35. AND ad.id IS NULL;
Add Comment
Please, Sign In to add comment