
- 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
Update a MySQL column with JSON format?
To display records like JSON format, use MySQL concat(). Let us first create a table −
mysql> create table DemoTable1373 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentDetails text -> ); Query OK, 0 rows affected (0.86 sec)
Insert some records in the table using insert command. Here, we haven’t inserted anything −
mysql> insert into DemoTable1373 values(); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable1373 values(); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1373 values(); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1373;
This will produce the following output −
+-----------+----------------+ | StudentId | StudentDetails | +-----------+----------------+ | 1 | NULL | | 2 | NULL | | 3 | NULL | +-----------+----------------+ 3 rows in set (0.00 sec)
Following is the query to update a MySQL field with JSON format −
mysql> update DemoTable1373 set StudentDetails=concat("{" "StudentName:", " John ,"," StudentAge:", 21,","," StudentCountryName: "," US","} "); Query OK, 3 rows affected (0.14 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check the table records once again −
mysql> select * from DemoTable1373;
This will produce the following output −
+-----------+---------------------------------------------------------------+ | StudentId | StudentDetails | +-----------+---------------------------------------------------------------+ | 1 | {StudentName: John , StudentAge:21, StudentCountryName: US} | | 2 | {StudentName: John , StudentAge:21, StudentCountryName: US} | | 3 | {StudentName: John , StudentAge:21, StudentCountryName: US} | +-----------+---------------------------------------------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Update a column of text with MySQL REPLACE()
- How to create JSON format with group-concat in MySQL?
- MySQL update a column with an int based on order?
- How to update MySQL column with random value?
- Update a column based on another MySQL table’s column
- MySQL UPDATE column names and set None values with N/A?
- Convert JSON to another JSON format with recursion JavaScript
- Update a column A if null, else update column B, else if both columns are not null do nothing with MySQL
- How to update records in a column with random numbers in MySQL?
- How to update a MySQL column by subtracting a value with some conditions?
- How to update the date format in MySQL?
- How to update a MySQL date type column?
- Update only a single column value in MySQL
- MySQL UPDATE the corresponding column with random number between 1-3?
- How to update a column with the same values (not all) using UPDATE, SET and LIMIT in MySQL?

Advertisements