SQL Query to get the related data in different table
06:41 06 Jun 2014

I have 5 table,

user, plan, achievement, user_plan, user_achievement

The strucutre

User
id
name

Plan
id
name

achievement
id
name
*planID

user_plan
*planid
*userid

user_achievement
*achievementid
*userid
*createDate

And I use Codeigniter (Doesn't matter , what I would like to have is the mysql query)

$this->db->select('*');
$this->db->from('user');
$query = $this->db->get();

Actually, for each plan , there is a list of achievement, if it is not achieved, it is not stored at the user_achievement, so how can I get "for each user, get 1) his name 2)the plan he joins, and 3)the achievement he achieve and not achieve (need to highlight the achieved)"?

Thanks.

php mysql codeigniter join query-builder