A
A
apple-apple2018-03-19 12:14:05
PHP
apple-apple, 2018-03-19 12:14:05

MySQL. How to make a larger/less selection in a column where JSON data is stored?

There is a column where JSON data is stored, the column type is VARCHAR.
For example, here is the dataset it contains:

{"show_title":"","link_titles":"","show_tags":"","show_intro":"","info_block_position":"","show_category":"","link_category":"","show_parent_category":"","link_parent_category":"","show_author":"","link_author":"","show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_icons":"","show_print_icon":"","show_email_icon":"","show_vote":"","show_hits":"","show_noauth":"","urls_position":"","alternative_readmore":"","article_layout":"","show_publishing_options":"","show_article_options":"","show_urls_images_backend":"","show_urls_images_frontend":""}

You need to select records where the value of the "power" parameter is greater than 0 and less than X.
Is it possible to do this with an SQL query, or do you need to select all records, then decode json data and check in a loop?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikolay, 2018-03-19
@apple-apple

Can this be done with a SQL query?

Your field type is varchar, so it's just text, mysql can't "parse" text, so
on the PHP side

V
Valery Chesnokov, 2018-03-22
@valerychesnokov

MySQL has a data type - JSON.
www.mysqltutorial.org/mysql-json has examples.
CREATE TABLE events(
id int auto_increment primary key,
event_name varchar(255),
visitor varchar(255),
properties json ,
browser json
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question