SELECT
    AP.AppointmentID,
    AP.AttendanceDate,
    PR.ProductCategory,
    PRA.ProductCategory as Category
FROM tbAppointments AP
INNER JOIN taClientProducts CP ON (AP.ClientID = CP.ClientID)
LEFT JOIN taProducts PR ON (CP.ProductID = PR.ProductID)    -- for cancel category
LEFT JOIN taProducts PRA ON (PRA.ProductID = AP.ProductID)  -- for appointment category
WHERE (CP.ClientProductID = @nClientProductID)
  AND ((AP.AppointmentStage = 'Appointment' OR AP.AppointmentStage = 'AuthReady') AND (PRA.ProductCategory = PR.ProductCategory))
  AND (AP.AttendanceDate >= NOW())
ORDER BY AP.AttendanceDate, AP.AppointmentID