- 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.)
- 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.)
- Deleting all rows from a table:
DELETE FROM table_name;
Example:
DELETE FROM employees;
Result:
All rows from the "employees" table will be deleted.
- 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.