タイトルに書かれているように:このSQLステートメントを正しく書く方法は?
select
sl.switch_ip,
sl.switch_name,
count(m.switch_ip) as macentries,
(select arpentries from (select sl1.switch_ip, sl1.switch_name, count(ar.switch_ip) as arpentries
from my_switchlist sl1
left Join my_arptable ar on ar.switch_ip = sl1.switch_ip
group by sl1.switch_ip,sl1.switch_name
order by sl1.switch_ip))
from my_switchlist sl
left Join my_mactable m on m.switch_ip = sl.switch_ip
group by sl.switch_ip,sl.switch_name
order by sl.switch_ip
選択と副選択は、別々に実行された場合は正常に機能します。しかし、それらを組み合わせるとすぐに、次のエラーが発生します。
Error: A subquery has returned not exactly one row.
SQLState: 21000
ErrorCode: -284
Position: 470