0

I am trying to return column invaliditycheck count for every user using a sub query but getting an error, can someone help:

Select
    Count(t1.battle_id) As total_battles,
    t1.battle_user,
    t2.competitions_title,
    t1.invaliditycheck,
    (Select
         Count(t3.invaliditycheck)
     From
         wp_battle_results As t3
     Where
         t3.invaliditycheck = 1 And
         t3.stealth_status = 0 And
         t3.demo = 0
     Group By
         t3.battle_user) As total_invalaidity
From
    wp_battle_results As t1
    Left Join wp_battle_competitions As t2
        On t1.competitions_id = t2.competitions_id
Group By
    t1.battle_user
Order By
    t1.battle_id Desc

When I am running this sub query separately, it's returning proper result.

Luuk
  • 12,245
  • 5
  • 22
  • 33
sanad qazi
  • 31
  • 5
  • You need a correlated subquery (also without GROUP BY.) Or LEFT JOIN the subquery instead. – jarlh Mar 17 '22 at 08:58
  • Please never use formatting codes like `**` in your code. – Luuk Mar 17 '22 at 09:01
  • "it's returning proper result" is a vague terminology. The subquery CAN return more than 1 row, and it does so when multiple `batller_user` exist. – Luuk Mar 17 '22 at 09:04

0 Answers0