I have a column inside my mysql table which contains following Json data.
var employees = [
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter","lastName": "Jones"}
];
Now I want to use this column data in my query like
select *
from tb1
left join tb2 on tb1.(this firstName inside my column) = tb2.firstName.
Is there a way to query JSON data in mysql server?
mySQL supports JSON however you must have column properly set as JSON (putting JSON string in varchar
/text
will NOT work. See docs: https://dev.mysql.com/doc/refman/5.7/en/json.html
Sure, but it won't be fast
SELECT *
FROM tb1
LEFT JOIN tb2 ON
UPPER(tb1.employee_column) LIKE (UPPER(CONCAT('%"firstName":"', tb2.firstName, '"%')))
Assuming you are using Mysql version 5.7 (json object type is not supported below that), and assuming your column is of type json, you can use this query:
SELECT * from tb1 where yourJsonColumn->'$.firsName' = 'yourDesiredFirstName';