Deleting Records via SQL Query in Python
The DELETE command lets you delete records from a table. Its syntax is similar to what you learned earlier:
query = "DELETE FROM table WHERE condition"
With the DELETE command, it is necessary to use the commit method:
with connection.cursor(dictionary=True) as cursor:
cursor.execute(query)
connection.commit()
Remove user with id equal to 7.
Remove all users who are 23 years old.
Remove all users whose id is greater than 5 and salary is greater than or equal to 900.
Delete all users.