Alternatively, You can use Conditional Left Joins.
It is simple.
You can see comprehensive post on MySQL conditional Joins at
mysqldiary.com/conditional-joins-in-mysql