![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
MySQL TINYINT type to return <>1 or IS NULL records
Let us first create a table −
mysql> create table DemoTable -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY , -> EmployeeName varchar(20), -> isMarried tinyint -> ); Query OK, 0 rows affected (0.83 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(EmployeeName,isMarried) values('Chris',NULL); Query OK, 1 row affected (0.76 sec) mysql> insert into DemoTable(EmployeeName,isMarried) values('David',1); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable(EmployeeName,isMarried) values('Mike',0); Query OK, 1 row affected (0.69 sec) mysql> insert into DemoTable(EmployeeName,isMarried) values('Sam',NULL); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(EmployeeName,isMarried) values('Bob',0); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------------+--------------+-----------+ | EmployeeId | EmployeeName | isMarried | +------------+--------------+-----------+ | 1 | Chris | NULL | | 2 | David | 1 | | 3 | Mike | 0 | | 4 | Sam | NULL | | 5 | Bob | 0 | +------------+--------------+-----------+ 5 rows in set (0.00 sec)
Here is the query to display records <> 1 or IS NULL −
mysql> select *from DemoTable where isMarried <> 1 or isMarried IS NULL;
This will produce the following output −
+------------+--------------+-----------+ | EmployeeId | EmployeeName | isMarried | +------------+--------------+-----------+ | 1 | Chris | NULL | | 3 | Mike | 0 | | 4 | Sam | NULL | | 5 | Bob | 0 | +------------+--------------+-----------+ 4 rows in set (0.00 sec)
Advertisements