Posted by: Denny Cherry
DELETE statement, SQL
When you have data in your table that you need to remove the DELETE statement is the way to do that. Using the DELETE statement without any WHERE clause will remove all the data from your table. The WHERE clause works the same way as the WHERE clause for SELECT and UPDATE statements.
DELETE FROM Employee
WHERE EmployeeId = 4
You can also JOIN to a table when you delete data from a table which allows you to use the second table within the filter. This requires a slightly different syntax than your normal DELETE syntax.
FROM Employee e
JOIN Department ON Employee.DepartmentId = Department.DepartmentId
AND Department.DepartmentName = 'Sales'
As you can see you need to set an alias for the table you are deleting from, and put that alias between the DELETE and FROM words.
P.S. Sorry this didn’t come up sooner, I could have sworn that I wrote it and published it back when I started the series.