
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL query to delete row
Use the DELETE to delete a row in MySQL. Let us first create a table −
mysql> create table DemoTable -> ( -> CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> CustomerName varchar(100), -> CustomerAge int -> ); Query OK, 0 rows affected (1.30 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(CustomerName,CustomerAge) values('John',33); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(CustomerName,CustomerAge) values('Bob',25); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(CustomerName,CustomerAge) values('David',28); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(CustomerName,CustomerAge) values('Carol',29); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+------------+--------------+-------------+ | CustomerId | CustomerName | CustomerAge | +------------+--------------+-------------+ | 1 | John | 33 | | 2 | Bob | 25 | | 3 | David | 28 | | 4 | Carol | 29 | +------------+--------------+-------------+ 4 rows in set (0.00 sec)
Following is the query to delete a row in MySQL −
mysql> delete from DemoTable where CustomerName='David' and CustomerAge=28; Query OK, 1 row affected (0.23 sec)
Let us check the table records once again −
mysql> select *from DemoTable;
Output
This will produce the following output −
+------------+--------------+-------------+ | CustomerId | CustomerName | CustomerAge | +------------+--------------+-------------+ | 1 | John | 33 | | 2 | Bob | 25 | | 4 | Carol | 29 | +------------+--------------+-------------+ 3 rows in set (0.00 sec)
- Related Articles
- MySQL query to delete a row if two columns are equal
- Delete selective multiple records using MySQL DELETE query
- MySQL query to insert row with date?
- MySQL query to select one specific row and another random row?\n
- Implement DELETE query in MySQL stored procedure
- Does deleting row from view delete row from base table in MySQL?
- How to find specific row with a MySQL query?
- MySQL query to get a specific row from rows
- MySQL query to select maximum and minimum salary row?
- MySQL query to delete a record with the lowest ID?
- MySQL query to delete all rows older than 30 days?
- MySQL query to generate row index (rank) in SELECT statement?
- MySQL query to return all items in a single row
- MySQL query to perform delete operation where id is the biggest?
- MySQL query to delete last two words from every column value

Advertisements