In SQL, the
WHERE clause is used alongside the
DELETE statement to delete a specified record from a table.
WHERE clause is commonly used with comparison operators. These include:
=(equal to operator)
!=(not equal to operator)
>(greater than operator)
<(less than operator)
>=(greater than or equal to operator)
<=(less than or equal to operator)
It is worth noting that:
WHEREclause has the primary key with the
=operator, then only one record can be affected —if they are found.
WHEREclause has the non-primary key with the
=operator, then multiple records can be affected —if they are found.
>, multiple records will be affected, if they are found.
The syntax of the
DELETE statement is given below:
DELETE FROM name_of_table WHERE condition;
The database we will be working with is shown below:
In the code written below, we will use the
WHERE clause alongside the
DELETE statement to delete a specific part of the
-- using the WHERE clause alongside the SELECT statement DELETE FROM Customers WHERE CustomerName='Benjamin Monday'; -- printing the modified table SELECT * FROM Customers
Customerstable and populate it with values, according to the defined database schema on our platform.
WHEREclause and the
DELETEstatement with a condition of where the
Note: Notice from the output of the code that the record which has the
Benjamin Mondayhas been deleted.
View all Courses