Time : 11:58:37 SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and FIRMNAME=12944 order by DISPATCHDATE DESC' at line 1 Raw SQL : select count(DISPATCHREGISTERID) as totalnew_parties from dispatchregister as ab,partydetail as p,(select PARTY as prty,CITY,addresstype from contact group by PARTY) as c where p.PARTYID=ab.FIRMNAME and p.PARTYID=c.prty and PARTYCODE= and FIRMNAME=12944 order by DISPATCHDATE DESC