
- 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 select ID column as null in MySQL?
Let us first create a table. The query to create a table is as follows
mysql> create table selectAllDemo - > ( - > Name varchar(100), - > Age int - > ); Query OK, 0 rows affected (1.90 sec)
Insert some records in the table using insert command.
The query is as follows
mysql> insert into selectAllDemo values('John',25); Query OK, 1 row affected (0.99 sec) mysql> insert into selectAllDemo values('Carol',26); Query OK, 1 row affected (0.42 sec) mysql> insert into selectAllDemo values('Bob',30); Query OK, 1 row affected (1.57 sec) mysql> insert into selectAllDemo values('Sam',35); Query OK, 1 row affected (0.26 sec)
Display all records from the table using select statement.
The query is as follows
mysql> select *from selectAllDemo;
The following is the output
+-------+------+ | Name | Age | +-------+------+ | John | 25 | | Carol | 26 | | Bob | 30 | | Sam | 35 | +-------+------+ 4 rows in set (0.16 sec)
Here is the query to select only the ID column as NULL
mysql> select NULL AS Id,tbl.Name,tbl.Age from selectAllDemo tbl where Age=35;
The following is the output
+------+------+------+ | Id | Name | Age | +------+------+------+ | NULL | Sam | 35 | +------+------+------+ 1 row in set (0.07 sec)
- Related Articles
- MySQL - SELECT … WHERE id IN (..) order with particular column?
- SELECT not null column from two columns in MySQL?
- How to use NULL in MySQL SELECT statement?
- MySQL select * with distinct id?
- SELECT WHERE IN null in MySQL?
- How to add a NOT NULL column in MySQL?
- Set the NULL values to 0 and display the entire column in a new column with MySQL SELECT
- How to insert NULL keyword as a value in a character type column of MySQL table having NOT NULL constraint?
- How to select everything before @ in an email-id with in MySQL?
- MySQL query to select distinct order by id
- Select the table name as a column in a UNION select query with MySQL?
- How to handle fragmentation of auto increment ID column in MySQL?
- How to SELECT * and rename a column in MySQL?
- How to add not null constraint to existing column in MySQL?
- Treat a MySQL column field as NULL if it is blank?

Advertisements