Error! 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 p.parent_page_id = pp.page_id' at line 1: SELECT p.*,pp.page_name theDate from page p, page pp WHERE p.page_id = AND p.parent_page_id = pp.page_id