0

I found an error: Subquery returns more than 1 row in my syntaq query:

SELECT  (SELECT username 
         FROM users 
         WHERE id_user = b.id_user) AS kdtk,
        (SELECT masalah 
         FROM kategori_masalah 
         WHERE id_kategori=a.id_kategori) AS masalah,
        (SELECT nama 
         FROM users 
         WHERE id_user = b.id_user) AS nama,
         b.id_dept AS asal,a.tujuan_id_dept AS tujuan,
         (SELECT COUNT(*) 
          FROM (SELECT d.id_kategori,e.id_user,d.id_detail,d.tgl_buat 
                FROM complaint d,detail_complaint e 
                WHERE d.id_kategori LIKE '%%' AND e.id_user LIKE '%%' AND d.id_detail=e.id_detail 
                      AND d.tgl_buat BETWEEN '2019-04-01 00:00:00' AND '2019-06-09 23:59:59') AS jumlah 
           WHERE id_detail=id_detail GROUP BY id_kategori,id_user)
FROM complaint a,detail_complaint b 
WHERE a.id_kategori LIKE '%%' AND b.id_user LIKE '%%' AND a.tujuan_id_dept='EDP' 
      AND a.id_detail=b.id_detail AND a.tgl_buat BETWEEN '2019-04-01 00:00:00' AND '2019-06-09 23:59:59' 
GROUP BY a.id_kategori,b.id_user 
ORDER BY kdtk;
nacho
  • 5,280
  • 2
  • 25
  • 34
  • 1
    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) – MrPromethee Jun 06 '19 at 08:18
  • 1
    If that's what mysql says then it must be true but with such a complex and no indication what it's supposed to do sample data would really help – P.Salmon Jun 06 '19 at 08:18
  • 1
    **a.id_kategori LIKE '%%' AND b.id_user LIKE '%%'** doesn't make any sense – nacho Jun 06 '19 at 08:20
  • Really, all the query doesn't make any sense, you should use JOINS instead of so many subqueries – nacho Jun 06 '19 at 08:45

0 Answers0