You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND mm.content_type='products' ORDER BY mm.media_sort' at line 1 SELECT m.media_meta FROM media_map mm JOIN media m ON m.media_id=mm.media_id WHERE mm.content_id= AND mm.content_type='products' ORDER BY mm.media_sort