
- 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
How to exclude a specific row from a table in MySQL?
Use <> i.e. not equal in MySQL to exclude a specific row from a table. Let us first create a table −
mysql> create table DemoTable -> ( -> Id int, -> FirstName varchar(100) -> ); Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(1,'John'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(2,'Chris'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(3,'Robert'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values(4,'David'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+------+-----------+ | Id | FirstName | +------+-----------+ | 1 | John | | 2 | Chris | | 3 | Robert | | 4 | David | +------+-----------+ 4 rows in set (0.00 sec)
Here is the query to exclude a specific row from the table −
mysql> select Id,FirstName from DemoTable where Id <> 2;
Ouptut
This will produce the following output −
+------+-----------+ | Id | FirstName | +------+-----------+ | 1 | John | | 3 | Robert | | 4 | David | +------+-----------+ 3 rows in set (0.00 sec)
- Related Articles
- Subquery to exclude a particular row in MySQL
- How do I exclude a specific record in MySQL?
- MySQL query to get a specific row from rows
- Display random row from a MySQL table
- Get only a single value from a specific MySQL row?
- How can we delete a single row from a MySQL table?
- How to count specific comma separated values in a row retrieved from MySQL database?
- How to find specific row with a MySQL query?
- How to add a row to a table using only strings from another table as reference in MySQL?
- MySQL query to exclude some of the values from the table
- Create a MySQL table from already created table selecting specific rows?
- How to count number of specific symbols in a row in MySQL?
- How can we fetch a particular row as output from a MySQL table?
- How to search a MySQL table for a specific string?
- How to delete a row from a table using jQuery?

Advertisements