3 PHP - Mysql Basics - PHP Tutorials

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 DRROP DATABASE function is used to delete databases. The syntax is DRROP DATABASE <database name>;.


DRROP DATABASE db1;

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 DRROP TABLE <table name>; command is executed.


DRROP TABLE table1;

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

Inserting data into MySQL <<  1 2 3
New Content