I have three table as:
Student: id,name
Lesson: id,name
Student_Lesson: student_id, lesson_id
I want to create a query such as:
Select s.name as student_name,
(
Select l.name
from Lesson as l
inner join Student_Lesson as sl on sl.lesson_id=l.id
where sl.student_id=s.id
) as lessons
from Student as s where <Complex query>
This gives the error:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
As expected, because there is more than one lesson attached with a student, can I concatenate all results and have a result such as:
_____________________________________________
| student_name | lessons |
| ----------------|-------------------------|
| Luke Skywalker | Physics,Chemistry |
| Han Solo | Mathematics,Physics |
|_________________|_________________________|
If I reduce the lesson count for all students to one this query works fine.
There may be a syntax error as I did refactor my query and I might have made some mistakes.