
- 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
SELECT WHERE IN null in MySQL?
Following is the syntax −
select yourColumnName1, yourColumnName2, yourColumnName3, . . . N from yourTableName where yourValue in(yourColumnName1,yourColumnName2) or yourColumnName1 is NULL;
Let us create a table −
mysql> create table demo60 −> ( −> id int not null auto_increment primary key, −> first_name varchar(20), −> last_name varchar(20) −> ) −> ; Query OK, 0 rows affected (2.11 sec)
Insert some records into the table with the help of insert command −
mysql> insert into demo60(first_name,last_name) values('John','Smith'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo60(first_name,last_name) values('John','Doe'); Query OK, 1 row affected (0.51 sec) mysql> insert into demo60(first_name,last_name) values(null,'Brown'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo60(first_name,last_name) values('David','Miller'); Query OK, 1 row affected (0.16 sec) mysql> insert into demo60(first_name,last_name) values('David','Smith'); Query OK, 1 row affected (0.11 sec) mysql> insert into demo60(first_name,last_name) values('Chris','Brown'); Query OK, 1 row affected (0.12 sec)
Display records from the table using select statement −
mysql> select *from demo60;
This will produce the following output −
+----+------------+-----------+ | id | first_name | last_name | +----+------------+-----------+ | 1 | John | Smith | | 2 | John | Doe | | 3 | NULL | Brown | | 4 | David | Miller | | 5 | David | Smith | | 6 | Chris | Brown | +----+------------+-----------+ 6 rows in set (0.00 sec)
Following is the query to select where in with NULL −
Mysql> select −> id, −> first_name, −> last_name −> from demo60 −> where 'John' in(first_name,last_name) or first_name is NULL;
This will produce the following output −
+----+------------+-----------+ | id | first_name | last_name | +----+------------+-----------+ | 1 | John | Smith | | 2 | John | Doe | | 3 | NULL | Brown | +----+------------+-----------+ 3 rows in set (0.00 sec)
- Related Articles
- How to use NULL in MySQL SELECT statement?
- MySQL Select where values IN List string?
- SELECT not null column from two columns in MySQL?
- How to select ID column as null in MySQL?
- SELECT where row value contains string in MySQL?
- Can we use SELECT NULL statement in a MySQL query?
- MySQL select query with multiple WHERE?
- MySQL - SELECT … WHERE id IN (..) order with particular column?
- SELECT * WHERE var == [one of many alternatives] in MySQL?
- MySQL Select where timestamp is in the current hour?
- SELECT a row by subtracting dates in WHERE in MySQL?
- Perform MySQL SELECT on fields containing null values?
- MySQL: selecting rows where a column is null?
- MySQL select query to fetch data with null value?
- Select a field and if it's null, select another with MySQL?

Advertisements