$ settings --editor

$ settings --general

$ save --settings

SQL for beginners

Deleting rows with DELETE #

The DELETE statement removes rows from a table:

DELETE FROM table_name
WHERE
    condition;
  • table_name: The table to delete rows from.
  • WHERE condition: Chooses which rows get deleted.
Never forget the WHERE clause

Just like UPDATE, leaving out WHERE means DELETE removes every single row in the table, not just some of them. Always double check your WHERE clause before running a DELETE.


Exercise #

We have already created a table orders with the columns id, customer_id, order_date, status, and shipped_date. Write a command that deletes every order whose status is Cancelled, without deleting any other order.

Tests #

  • No row in orders has status equal to Cancelled anymore.
  • Every order that was not Cancelled is still in the table.
Solution
DELETE FROM orders
WHERE
    status = 'Cancelled';
Output will be displayed here