How to fix this mysql query
SELECT no, name,
(SELECT chapter, max FROM table2 WHERE name = user.name AND max = 10) as sub_array1,
(SELECT chapter, max FROM table2 WHERE name = user.name AND max = 20) as sub_array2
FROM user ORDER by exp DESC
example expected out result:
the current query returns me Operand should contain 1 column(s)
basically i want to create something like this:
------------------------------------------------------------------------------
no | name | sub_array1
------------------------------------------------------------------------------
1 |myname | sub_array1[0][chapter]=chapter_1, sub_array1[0][max]=100
| | sub_array1[1][chapter]=chapter_2, sub_array1[1][max]=70
| | ...
------------------------------------------------------------------------------
2 |myname_2 | sub_array1[0][chapter]=chapter_1, sub_array1[0][max]=100
| | sub_array1[1][chapter]=chapter_2, sub_array1[1][max]=50
| | sub_array1[2][chapter]=chapter_3, sub_array1[2][max]=60
Actual query
SELECT no, name, maxcombo, exp, level, location,
((SELECT chapter, MAX(score) as max, name FROM chapter_test_progress WHERE name = user.name AND type = 'vocabulary' GROUP BY chapter)) as user_chapter_test_statuses,
((SELECT chapter, MAX(score) as max, name FROM chapter_test_progress WHERE name = user.name AND type = 'kanji' GROUP BY chapter)) as user_chapter_test_status_kanjis
FROM user ORDER by exp DESC LIMIT $offset, $rowPerPage
Thank You,