In today’s article, we will talk about the use of the ‘Delete’ command to delete one or more data in a Table.
DELETE helps you to delete all the data in the table or the affected records according to the condition you specify.
Its general usage is as follows.
1 |
DELETE FROM table WHERE requested_condition; |
If the DELETE clause is executed without adding the where condition, all the data in the table is DELETED.
Since we will work in the ogrenci_d1 table, let’s look at the data in the table.
Let’s delete all the data specified in the ogrenci_d1 table with DELETE.
1 |
DELETE FROM ogrenci_d1; |
What should I do if I want to delete the student whose name is Faruk? We will use the where condition right here, let’s make our example of the where condition.
1 |
DELETE FROM ogrenci_d1 WHERE name='Faruk'; |
As seen above, our record named Faruk is not visible.
We can use the RETURNING command to see the deleted data, let’s delete one more data, but let’s see the deleted data by using the RETURNING command.
1 |
DELETE FROM ogrenci_d1 WHERE name='Ogun' RETURNING *; |
As seen in the picture above, we deleted our data and let’s look at the output of the deleted data by selecting our table.