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 (sid<>997) and (rfg_stories.sid=rfg_thumb.id_table) and (rfg_thumb.table_n' at line 1