Invalid query: select * from persons_occupations,persons,occupations where persons_occupations.person_id = and persons_occupations.person_id=persons.person_id and persons_occupations.occupation_id=occupations.occupation_id 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 persons_occupations.person_id=persons.person_id and persons_occupatio' at line 3