Skip to content

Latest commit

 

History

History
90 lines (64 loc) · 1.34 KB

delete-data.md

File metadata and controls

90 lines (64 loc) · 1.34 KB
  1. DELETE:

Explanation: DELETE is used to delete existing rows from a table.

Syntax:

DELETE
FROM
    table_name1
WHERE
    column_name1 = specific_value1;

Example:

DELETE
FROM
    salary_appraisal
WHERE
    emp_no = '100010';

Result:

2 rows affected. (Query took 0.0910 seconds.)
  1. DELETE JOIN:

Explanation: DELETE JOIN is used to delete rows from a table based on a join with another table.

Syntax:

DELETE
    table_name1
FROM
    table_name1
JOIN table_name2 ON table_name1.column_name1 = table_name2.column_name2;

Example:

DELETE
    salary_appraisal
FROM
    salary_appraisal
JOIN employees ON salary_appraisal.emp_no = employees.emp_no;

Result:

3 rows affected. (Query took 0.0950 seconds.)
  1. Deleting all rows from a table:
DELETE FROM table_name;

Example:

DELETE FROM employees;

Result:

All rows from the "employees" table will be deleted.

  1. Deleting data using a subquery:
DELETE FROM table_name WHERE column_name IN (SELECT column_name FROM other_table WHERE condition);

Example:

DELETE FROM employees WHERE emp_id IN (SELECT emp_id FROM terminated_employees);

Result:

All rows from the "employees" table where the "emp_id" column matches any value from the "terminated_employees" table will be deleted.