The table structure is as follows: id varchar(32) info json data: id = 1 info = {"age": "18","disname":"Xiao Ming"} -------------------------------------------- Now I need to get the value of disanme in info. The query method is: 1. select t.id,JSON_EXTRACT(t.info,'$.disname') as disname from tableName t where 1=1 result:
The disname value found in the above SQL statement contains double quotes. Sometimes we don't need double quotes. In this case, we need to use the following method. 2. select t.id,t.info ->> '$.disname' as disname from tableName t where 1=1 result: id = 1 , disname = Xiao Ming ps: Let's look at the mysql query json field Create table statement Create Table CREATE TABLE `test` ( `id` int(10) , `user` json DEFAULT NULL COMMENT 'User information', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 Inserting Data It should be noted that single quotes are required outside the JSON data to distinguish INSERT INTO test (id,USER) VALUES(1,'{"name": "tom", "age": 18, "money": 3000}'); INSERT INTO test (id,USER) VALUES(2,'{"name": "jack", "age": 20, "money": 100}'); INSERT INTO test (id,USER) VALUES(3,'{"name": "tony", "age": 21, "money": 100}'); INSERT INTO test (id,USER) VALUES(4,'{"name": "danny", "age": 21, "money": 20}'); INSERT INTO test (id,USER) VALUES(5,'{"name": "janny", "age": 23, "money": 20}'); The table data is as follows Query Statement SELECT id,JSON_EXTRACT(USER,'$.name')FROM test; Here are the query results Summarize The above are two query methods introduced by the editor when the MySQL query field type is json. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: How to customize an EventEmitter in node.js
>>: How to use Docker to build a tomcat cluster using nginx (with pictures and text)
Table of contents 1. Concept 2. Environmental Des...
For example, users who need screen reading softwar...
Preface Recently, I encountered such a problem wh...
In daily work, we often need to view logs. For ex...
This article is an integrated article on how to c...
Three functions: 1. Automatic vertical centering o...
HTML provides five space entities with different ...
The previous article introduced several methods f...
Prepare the database (MySQL). If you already have...
Table of contents 1. The concept of filter 1. Cus...
How to install MySQL 5.7 in Ubuntu 16.04? Install...
Table of contents Jenkins installation Install Ch...
Previous This is a classic old question. Since a ...
Description of port availability detection when p...
Box-sizing in CSS3 (content-box and border-box) T...