php Tutorials
Creating An RSS Feed With PHP And MySQL
Retrieving XML With Curl and SimpleXML
Using curl to Query Remote Servers
MySQL Basics
PHP mySQL Voting Booth
File Download Security
PHP Fundamentals

MySQL Basics

Removing data from MySQL

DELETE Queries

So far we've covered how to put data into the database and how to modify it, but now we're going to start deleting data. The syntax is DELETE FROM <table> WHERE <field>=<value> LIMIT <number of rows>;. Here we're introducing the LIMIT statement, which is used in this situation to LIMIT the rows to delete. The LIMIT statement can also be used in other queries such as INSERT and UPDATE. LIMIT statements cannot be used in multi-table deletes.

DELETE FROM table1 WHERE field1>3;

Simple delete statement that deletes all rows from table1 where field1 is greater than 3.

DELETE FROM table1 WHERE field2>field4 LIMIT 5;

In this delete statement we delete the first 5 rows where field2 is greater than field4.

DELETE FROM table1,table2 WHERE table1.field3>table2.field3-5;

This statement deletes any row from table1 where field3 is greater than field3 of table2 minus 5.

Deleting Databases

The DROP DATABASE function is used to delete databases. The syntax is DROP DATABASE <database name>;.


This deletes the database db1 and all tables in the database.

Deleting Tables

Deleting tables is much like deleting databases. All data in the table will deleted along with the structure when the DROP TABLE <table name>; command is executed.

DROP TABLE table1;

This deletes the table table1 and all data in the table.

Inserting data into MySQL <<  1 2 3
New Content