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.
DELETE
FROM episodes
WHERE
series_id = 2
AND season_id = 5
AND episode_id = 12
;
COMMIT;
-- View result:
SELECT * FROM episodes WHERE series_id = 2 AND season_id = 5;
-- YDB doesn't see changes that take place at the start of the transaction,
-- which is why it first performs a read. It is impossible to execute UPDATE or DELETE on
-- if the table was changed within the current transaction. UPDATE ON and
-- DELETE ON let you read, update, and delete multiple rows from one table
-- within a single transaction.
$to_delete = (
SELECT series_id, season_id, episode_id
FROM episodes
WHERE series_id = 1 AND season_id = 1 AND episode_id = 2
);
SELECT * FROM episodes WHERE series_id = 1 AND season_id = 1;
DELETE FROM episodes ON
SELECT * FROM $to_delete;
COMMIT;
-- View result:
SELECT * FROM episodes WHERE series_id = 1 AND season_id = 1;
COMMIT;