SELECT A.CategoryId,LogPackageDetail, Category AS Category, LogPackageId, LogPackageTitle AS LogPackageTitle, LogPackagePrice, IF(DeliveryTime IS NULL OR DeliveryTime = '', '-', DeliveryTime) AS DeliveryTime FROM tbl_log_package_category Cat, tbl_log_packages A WHERE Cat.CategoryId = A.CategoryId AND DisableLogPackage = 0 AND DisableCategory=0 AND LogPackageId= ORDER BY OrderBy, Category, LogPackageTitle LIMIT 1 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 'ORDER BY OrderBy, Category, LogPackageTitle LIMIT 1' at line 2