SQLSTATE[42000]: Syntax error or access violation: 1064 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 's realty' group by user.agent_id ORDER BY user.firstname, user.lastname ASC' at line 16 The SQL being executed was: select user.firstname, user.lastname, agent_id as id, user.id as user_id from user INNER JOIN agent on user.agent_id = agent.id LEFT JOIN agent as sagent ON sagent.id = user.agent_id LEFT JOIN (SELECT * from brn where brn.date_deleted IS NULL GROUP BY brn.brn) AS sbrn ON sbrn.brn = sagent.brn LEFT JOIN agency as sagency ON sagency.id = sbrn.agency_id and sagency.date_deleted IS NULL INNER JOIN country as nationality on nationality.id = agent.nationality_id where user.user_type_id = 3 and user.user_status_id = 2 and user.date_deleted is null and user.country_id = 1 and sagency.name = 'gulf sotheby's realty' group by user.agent_id ORDER BY user.firstname, user.lastname ASC