
- 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
Is there any way to use values from a JSON object in a MySQL Select statement?
Yes, you can use json_extract(). Let us first create a table −
mysql> create table DemoTable -> ( -> Data json -> ); Query OK, 0 rows affected (0.63 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('{"Name": "John", "CountryName": "US"}'); Query OK, 1 row affected (0.33 sec) mysql> insert into DemoTable values('{"Name": "Chris", "CountryName": "UK"}'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+----------------------------------------+ | Data | +----------------------------------------+ | {"Name": "John", "CountryName": "US"} | | {"Name": "Chris", "CountryName": "UK"} | +----------------------------------------+ 2 rows in set (0.01 sec)
Following is the query to use values from a JSON object in a MySQL Select statement −
mysql> SELECT *from DemoTable WHERE json_extract(Data, '$.CountryName') like '%US%';
Output
+---------------------------------------+ | Data | +---------------------------------------+ | {"Name": "John", "CountryName": "US"} | +---------------------------------------+ 1 row in set (0.00 sec)
- Related Articles
- How to select values from a JSON object using jQuery?
- Is there a way to select a value which matches partially in MySQL?
- Is there a way to name columns in an INSERT statement in MySQL?
- Is there any way to check if there is a null value in an object or array in JavaScript?
- Is there any way in MongoDB to get the inner value of json data?
- Is there any easy way to add multiple records in a single MySQL query?
- How to use a select statement while updating in MySQL?
- Is there a way to make a list from a MySQL table in Java?
- How to use the CAST function in a MySQL SELECT statement?
- Is there a way to subtract number of days from a date in MySQL?
- How to use NULL in MySQL SELECT statement?
- Storing value from a MySQL SELECT statement to a variable?
- Is there such thing as a SELECT with an IF/ELSE statement in MySQL?
- Can we use SELECT NULL statement in a MySQL query?
- Is there a need to insert auto_increment column values in MySQL while using INSERT statement?

Advertisements