I have two tables, and I want to use a value from primary table (here: person.ref) to extract some data from a json field in a secondary table (here: person_details):
create table person (
id int(8),
ref varchar(20),
primary key (id)
);
create table person_details (
id int(8),
details json,
primary key (id)
);
SELECT JSON_EXTRACT(details, CONCAT('$.', p.ref))
FROM person p
JOIN person_details d using (id);
The person_details data is like:
{
"ref1": {
...
}
}
But that does not matter, because the sql statement itself seems to be invalid:
Result:
#3143 - Invalid JSON path expression. The error is around character position 12.
Why?