i'm trying to build query that can find out who not visit a stage after he visit the first stage.
Clients Table:
Plays table:
Tickets table:
+-----+----------------------+-------------------+------+------+
| CID | PLAY | SHOWTIME | SEAT | COST |
+-----+----------------------+-------------------+------+------+
| 1 | Cats | 03/11/21 12:00:00 | 22 | 350 |
+-----+----------------------+-------------------+------+------+
| 2 | Phantom of the Opera | 02/11/21 15:00:00 | 44 | 150 |
+-----+----------------------+-------------------+------+------+
| 3 | Hamilton | 02/11/21 15:00:00 | 123 | 450 |
+-----+----------------------+-------------------+------+------+
| 4 | Phantom of the Opera | 02/11/21 15:00:00 | 34 | 250 |
+-----+----------------------+-------------------+------+------+
| 3 | Hamilton | 02/11/21 15:00:00 | 5 | 600 |
+-----+----------------------+-------------------+------+------+
| 2 | Phantom of the Opera | 02/11/21 15:00:00 | 6 | 70 |
+-----+----------------------+-------------------+------+------+
| 1 | Tina | 02/11/21 17:00:00 | 33 | 450 |
+-----+----------------------+-------------------+------+------+
so i have tired by first filter all clients that visit in A Stage. but i could not findout how to check if who also not visit in C Stage after he was in A Stage by date. any insight here?
SELECT cid,name
FROM(
SELECT tickets.cid,plays.play,tickets.showtime,clients.name,plays.stage
from TICKETS
INNER JOIN plays ON plays.play=tickets.play AND plays.showtime=tickets.showtime AND plays.stage='A'
INNER JOIN clients ON tickets.cid=clients.cid)
desire result: as you can see client with cid =1, not in the result becuse he visit in A stage and then he Visit in C stage
╔═════╦══════╗
║ cid ║ name ║
╠═════╬══════╣
║ 2 ║ Lior ║
╠═════╬══════╣
║ 3 ║ Josh ║
╠═════╬══════╣
║ 4 ║ Haim ║
╚═════╩══════╝