CREATE PROCEDURE `spGetComment` ( IN `P_AssignContentId` INTEGER , IN `P_CommentId` INTEGER ) BEGIN SELECT `UserId` , `tstudymaterialcomment` . `Id` AS `CommentId` , `tuser` . `name` AS `UserName` , ( SELECT COUNT (?) FROM `tstudymaterialcomment` `ts` WHERE `ts` . `ReferenceCommentId` = `tstudymaterialcomment` . `id` ) AS `NumberofComment` , `CommentDetail` AS `CommentMessage` , `tstudymaterialcomment` . `CreatedDateTime` FROM `tstudymaterialcomment` LEFT JOIN `tuser` ON `UserId` = `tuser` . `Id` WHERE ( `tstudymaterialcomment` . `Id` = `P_CommentId` OR `ReferenceCommentId` = `P_CommentId` ) OR ( `P_CommentId` = ? AND `ReferenceCommentId` = ? ) AND `AssignContentId` = `P_AssignContentId` GROUP BY `tstudymaterialcomment` . `Id` ; END 