3

Trying to create a json_object containing json_array from mysql workbench.

The following statement results in "Error Code: 1242. Subquery returns more than 1 row":

SELECT JSON_OBJECT('id', id, 
            'username', username, 
            'email', email, 
            'firstname', firstname, 
            'lastname', lastname, 
            'password', password, 
            'created', created, 
            'class_codes', (select JSON_ARRAY('id', id, 'code', code, 'created', created, 'fk_teacher', fk_teacher) from class_codes where fk_teacher=teachers.id)) FROM teachers where teachers.id=18;

Not sure how to fix it.

Jinesh
  • 95
  • 6
  • Possible duplicate of [Solution to "subquery returns more than 1 row" error](https://stackoverflow.com/questions/28171474/solution-to-subquery-returns-more-than-1-row-error) – René Höhle Mar 19 '18 at 19:33
  • 1
    Not sure if that solution would work for json return type – Jinesh Mar 19 '18 at 20:09

0 Answers0