
- 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 query JSON datatype in MySQL?
Use JSON data type from MySQL to work with JSON. Let us first create a table −
mysql> create table DemoTable -> ( -> StudentName json -> ); Query OK, 0 rows affected (0.74 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('["John", "Chris", "Robert","David","Sam"]'); Query OK, 1 row affected (0.33 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+---------------------------------------------+ | StudentName | +---------------------------------------------+ | ["John", "Chris", "Robert", "David", "Sam"] | +---------------------------------------------+ 1 row in set (0.00 sec)
Here is how you can query JSON data type −
mysql> SELECT *from DemoTable WHERE JSON_CONTAINS(StudentName, '["Chris"]');
Output
This will produce the following output −
+---------------------------------------------+ | StudentName | +---------------------------------------------+ | ["John", "Chris", "Robert", "David", "Sam"] | +---------------------------------------------+ 1 row in set (0.04 sec)
- Related Articles
- How to sum rows of VARCHAR datatype or TIME datatype in MySQL?
- How to define and query json columns in PostgreSQL?
- How to get the datatype of MySQL table columns?
- How to store data in MySQL as JSON?
- How to set NOW() as default value for datetime datatype in MySQL?
- How to query soundex() in MySQL?
- Using Time datatype in MySQL without seconds?
- How to save JSON array to MySQL database?
- MySQL datatype to store month and year only?
- For timestamp, which datatype is used in MySQL?
- How to treat MySQL longtext as integer in MySQL query?
- How to create JSON format with group-concat in MySQL?
- How to convert MySQL DATETIME value to JSON format in JavaScript?
- Change a MySQL Column datatype from text to timestamp?
- What is the MySQL datatype to store DATALINK object in JDBC

Advertisements