Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a where query for Json in mysql with key having a white space in between the name

Tags:

json

php

mysql

With json as

{ "First Name": {"nickname" : "Abc"} }

in json column 'name' of mysql database.

How do I extract such rows in mysql.

Select * from users where name."$.First Name.nickname" = "abc";

won't work. Any solution because I cannot change the json structure in database.

like image 619
Y M Avatar asked Dec 02 '22 14:12

Y M


1 Answers

Found the answer:

Select * from users where name."$.""First Name"".nickname" = "abc";

you need to double quote the key of JSON with a space.

like image 52
Y M Avatar answered Dec 05 '22 03:12

Y M