Operand should contain 1 column

353 Views Asked by At

Hello i try to run this query but this error come up

#1241 - Operand should contain 1 column(s)

here is the code :

SELECT 

(SELECT kk.namakk, anggkk.nama AS istri
FROM kk
JOIN anggkk
USING ( idkk ) 
WHERE anggkk.hubungan =  "istri"),

(SELECT anggkk.nama AS anak, YEAR( CURDATE( ) ) - YEAR( anggkk.ttl ) AS usia_anak
FROM anggkk
JOIN kk
USING ( idkk ) 
WHERE anggkk.hubungan =  "anak")

FROM kk, anggkk
GROUP BY kk.idkk

where is my error? thanks for the help!

1

There are 1 best solutions below

0
On

Operand should contain 1 column(s) , means you have many columns returned in your subqueries.

you need to add limit 1 to be just one column like that

   SELECT 

 (SELECT kk.namakk, anggkk.nama AS istri
 FROM kk
 JOIN anggkk
 USING ( idkk ) 
 WHERE anggkk.hubungan =  "istri"
 LIMIT 1),

 (SELECT anggkk.nama AS anak, YEAR( CURDATE( ) ) - YEAR( anggkk.ttl ) AS usia_anak
 FROM anggkk
 JOIN kk
 USING ( idkk ) 
 WHERE anggkk.hubungan =  "anak"
 LIMIT 1)

 FROM kk, anggkk
 GROUP BY kk.idkk

or you have to be more specified on what you selecting to be one column