SELECT DISTINCT RP.* FROM `rider_and_company_relationships` RACR, `rider_profiles` RP WHERE RACR.`company_id` = AND RACR.`relationship_status` = 'Accepted' AND RACR.`rider_status` = 'Accepted' AND RACR.`rider_id` = RP.`id` AND RP.`profile_pic` != '' ORDER BY RAND() LIMIT 10 : 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 RACR.`relationship_status` = 'Accepted' AND RACR.`rider_st' at line 4