- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements