Time : 10:02:18 SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'and FIRMNAME=17228 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=17228 order by DISPATCHDATE DESC