Question : Query is giving a non-boolean type specified error

Regarding the query below I get this error Msg 4145, Level 15, State 1, Line 7
An expression of non-boolean type specified in a context where a condition is expected, near ')'.  

The error is hapening in the last line.

Select Cli_Number
from (Select A.Cli_number, count(C.contact_id) as totalContacts from cli_clients a
JOIN dbo.cnt_Xref B
      ON A.Cli_Number = B.Cli_Number
JOIN cnt_Contacts C
      ON C.contact_id = B.contact_id group by A.Cli_Number)z
group by a.Cli_Number having max(totalContacts)

Answer : Query is giving a non-boolean type specified error

Correction:

 Select TOP 1 A.Cli_number, count(C.contact_id) as totalContacts
  from cli_clients A
          JOIN dbo.cnt_Xref B ON A.Cli_Number = B.Cli_Number
          JOIN cnt_Contacts C ON C.contact_id = B.contact_id group by A.Cli_Number
  group by A.Cli_Number
  ORDER BY count(C.contact_id) DESC
Random Solutions  
 
programming4us programming4us