Query SELECT m.id, m.photographer, m.photographer_link , list.module_id AS module_id,list.time AS time,list.created AS created,list.updated AS updated,list.user_id AS user_id,list.published AS published,list.published_time AS published_time,list.cat_1 AS cat_1,list.cat_2 AS cat_2,list.multipage AS multipage , list_info.name AS name,list_info.file_preview AS file_preview,list_info.file_main AS file_main,list_info.file_full AS file_full,list_info.file_small AS file_small,list_info.seo_url_name AS seo_url_name,list_info.seo_url_redirect AS seo_url_redirect,list_info.preview AS preview,list_info.count_likes AS count_likes,list_info.count_comments AS count_comments,list_info.count_views AS count_views,list_info.no_search AS no_search,list_info.show_in_mobile AS show_in_mobile , user_info.id AS user_info_id,user_info.name AS user_info_name,user_info.photo_100 AS user_info_photo_100 , file_preview.id AS file_preview_id,file_preview.way AS file_preview_way,file_preview.type AS file_preview_type,file_preview.server_id AS file_preview_server_id,file_preview.extra AS file_preview_extra , file_main.id AS file_main_id,file_main.way AS file_main_way,file_main.type AS file_main_type,file_main.server_id AS file_main_server_id,file_main.extra AS file_main_extra,file_main.name AS file_main_name from `cms_news_items_299` AS m LEFT JOIN `cms_items` AS list ON m.id = list.id LEFT JOIN `cms_items_info` AS list_info ON m.id = list_info.id LEFT OUTER JOIN `cms_users_info` AS user_info ON list.user_id = user_info.id LEFT OUTER JOIN `cms_files` AS file_preview ON list_info.file_preview = file_preview.id LEFT OUTER JOIN `cms_files` AS file_main ON list_info.file_main=file_main.id WHERE list.published = 1 AND list.time < ORDER BY list.time DESC,list.id DESC LIMIT 1 genereated this: 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 list.time DESC,list.id DESC LIMIT 1' at line 1