SELECT * FROM (

  SELECT
    U1.UserID,
    U1.Office365Email,
    U1.FullName,
    COALESCE(U1.MapReference, '') AS MapReference,
    IF(U1.UserID = @nConsultantID, 1, 0) AS IsSelectedUser,
    X.PresentationCount AS ProspectPresentationCount,
    IF(COALESCE(Y.PresentationCount, 0) < 5, 0, COALESCE(Y.PresentationCount, 0)) AS PresentationCount
  FROM
    taUsers AS U1

      -- Prospect Presentations.
      LEFT JOIN (
        SELECT
          ConsultantID AS UserID,
          COUNT(*) AS PresentationCount
        FROM
          taPresentation
        WHERE
          (AttendanceDate >= DATE_SUB(NOW(), INTERVAL 12 MONTH)) AND
          (ProspectID = @nProspectID)
        GROUP BY
          ConsultantID
      ) AS X USING (UserID)

      -- Presentations.
      LEFT JOIN (
        SELECT
          ConsultantID AS UserID,
          COUNT(*) AS PresentationCount
        FROM
          taPresentation
        WHERE
          (AttendanceDate >= DATE_SUB(NOW(), INTERVAL 12 MONTH))
        GROUP BY
          ConsultantID
      ) AS Y USING (UserID)
  WHERE
    (U1.Status = 1) AND
    (U1.IsResource = 0)

) AS Z
WHERE
  (Z.UserID = @nConsultantID) OR
  (Z.ProspectPresentationCount > 0) OR
  (Z.PresentationCount > 0)
ORDER BY
  5 DESC,
  6 DESC,
  7 DESC
LIMIT @nMaxCount