
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 UPDATE column names and set None values with N/A?
Let us first create a table −
mysql> create table DemoTable1903 ( FirstName varchar(20), LastName varchar(20) , Age int ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1903 values('John','Smith',23); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1903 values('None','Miller',28); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1903 values('None','Taylor',26); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1903 values('Chris','Brown',26); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1903;
This will produce the following output −
+-----------+----------+------+ | FirstName | LastName | Age | +-----------+----------+------+ | John | Smith | 23 | | None | Miller | 28 | | None | Taylor | 26 | | Chris | Brown | 26 | +-----------+----------+------+ 4 rows in set (0.00 sec)
Here is the query to update column names and set NONE with N/A −
mysql> update DemoTable1903 set FirstName='N/A' where FirstName='None'; Query OK, 2 rows affected (0.00 sec) Rows matched: 2 Changed: 2 Warnings: 0
Let us check the table records once again −
mysql> select * from DemoTable1903;
This will produce the following output −
+-----------+----------+------+ | FirstName | LastName | Age | +-----------+----------+------+ | John | Smith | 23 | | N/A | Miller | 28 | | N/A | Taylor | 26 | | Chris | Brown | 26 | +-----------+----------+------+ 4 rows in set (0.00 sec)
- Related Questions & Answers
- How to update a column with the same values (not all) using UPDATE, SET and LIMIT in MySQL?
- Set Blank spaces in column names with MySQL?
- Fetch specific rows from a MySQL table with duplicate column values (names)?
- Update a column in MySQL and remove the trailing underscore values
- Set particular value of column without using update and while inserting values in MySQL
- Update a MySQL column with JSON format?
- Setting column values as column names in the MySQL query result?
- Display month names and year from a column with date records with MySQL
- Lower case column names with MySQL SELECT?
- MySQL update column to NULL for blank values
- Update a column of text with MySQL REPLACE()
- MySQL regular expression to update a table with column values including string, numbers and special characters
- How to set MySQL default value NONE?
- Python - Create a dictionary using list with none values
- How to update a MySQL table by swapping two column values?
Advertisements