Deleting data
Delete data from the table using DELETE.
Note
We assume that you already created tables in step Creating a table and populated them with data in step Adding data to a table.
1. DELETE
2. FROM episodes
3. WHERE
4. series_id = 2
5. AND season_id = 5
6. AND episode_id = 12
7. ;
9. COMMIT;
11. -- View result:
12. SELECT * FROM episodes WHERE series_id = 2 AND season_id = 5;
14. -- YDB doesn't see changes that take place at the start of the transaction,
15. -- which is why it first performs a read. It is impossible to execute UPDATE or DELETE on
16. -- if the table was changed within the current transaction. UPDATE ON and
17. -- DELETE ON let you read, update, and delete multiple rows from one table
18. -- within a single transaction.
20. $to_delete = (
21. SELECT series_id, season_id, episode_id
22. FROM episodes
23. WHERE series_id = 1 AND season_id = 1 AND episode_id = 2
24. );
26. SELECT * FROM episodes WHERE series_id = 1 AND season_id = 1;
28. DELETE FROM episodes ON
29. SELECT * FROM $to_delete;
31. COMMIT;
33. -- View result:
34. SELECT * FROM episodes WHERE series_id = 1 AND season_id = 1;
36. COMMIT;

