I’m new to MySql queries:
Below is what I’m having issues with.
So I’m saving json_data as:
I’m using PHP json_encode to convert the array into JSON formate and store it directly in the data column.
id | data |
---|---|
1 | {"abc": 123, "947": 234, "874": 123} |
2 | {"abc": 369, "659": 123, "523": 123} |
I just want to get the total no of users (COUNT) that have the value 123
in their Data Column.
Thanks in advance.
2
Answers
You may use JSON_SEARCH() function. But it searches for string-type data only. Hence for to create effective query you must store the values into your JSON as strings, not as numbers.
db<>fiddle here
you can try it also by PHP
after you made your sql query, you get you object $YOUR_USER_SQL_ARRAY
this way you can get the number of 123 for all users, even if there is more than "123" for each user