您好我尝试运行此查询但出现此错误
#1241 - Operand should contain 1 column(s)
这是代码:
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
我的错误在哪里?谢谢你的帮助!
答案 0 :(得分:0)
Operand should contain 1 column(s)
,表示您的子查询中返回了许多列。
您需要将限制1添加为只有一列
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
或者您必须更多地指定您选择成为一列的内容