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 'GROUP BY pit.DESCRIPTION,pi.INV_DATE order by date DESC' at line 5 SELECT pit.DESCRIPTION,pit.PRICE,count(*) as QUANTITY,pi.INV_DATE as date FROM P_INVOICE_ITEMS pit inner join P_INVOICES pi on pi.INID=pit.INID inner join SOUNDS sd on sd.SOUNDID=pit.SOUNDID where sd.CRID= GROUP BY pit.DESCRIPTION,pi.INV_DATE order by date DESC