Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DROP TABLE IF EXISTS appointments;
- CREATE TABLE appointments (
- id integer,
- title varchar(255),
- created_at date
- );
- DROP TABLE IF EXISTS appointment_dates;
- CREATE TABLE appointment_dates (
- id integer,
- appointment_id integer,
- confirmed boolean
- );
- INSERT INTO appointments VALUES (1, 'one', '2018-05-21');
- INSERT INTO appointment_dates VALUES (1, 1, false);
- INSERT INTO appointment_dates VALUES (2, 1, true);
- INSERT INTO appointments VALUES (2, 'two', '2018-05-21');
- INSERT INTO appointment_dates VALUES (3, 2, false);
- INSERT INTO appointment_dates VALUES (4, 2, false);
- INSERT INTO appointments VALUES (3, 'three', '2018-05-22');
- INSERT INTO appointment_dates VALUES (4, 3, false);
- INSERT INTO appointment_dates VALUES (5, 3, false);
- INSERT INTO appointments VALUES (4, 'four', '2018-05-21');
- SELECT *
- FROM appointments a
- LEFT JOIN appointment_dates ad
- ON a.id = ad.appointment_id
- AND ad.confirmed = true
- WHERE a.created_at = '2018-05-21'
- AND ad.id IS NULL;
Add Comment
Please, Sign In to add comment