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 'ORDER BY t1.type_id DESC, RAND() LIMIT 3' at line 4
SELECT DISTINCT(t1.star_id), t1.id, t1.star_id, t1.type_id FROM vp_photo_lib_stars t1, vp_stars t2 WHERE 1 AND t1.type_id <> 1 AND t1.star_id <> 174 AND t2.id=t1.star_id AND t2.gender_id= ORDER BY t1.type_id DESC, RAND() LIMIT 3