Can't join the same table twice..

Hello.

How is it that, when i try to join a table twice, it only joins the second table, and ignores the first one?

This is my code:

$user = self::query()
        ->columns(array('COUNT(today.day) as day', 'COUNT(month.month) as month', 'Users.id'))
        ->join('Blogs', 'Users.id = Blogs.userid')

        ->join('Statistics', 'Blogs.id = today.blogid AND today.day = 22', 'today') // THIS get's replaced...
        ->join('Statistics', 'Blogs.id = month.blogid AND month.month = 1', 'month') // THIS works


        ->where('Users.id = :userid:', array('userid' => $id))
        ->orderBy('Users.id DESC')
        ->limit('1')
        ->execute();

    return $user;
edited Nov '15

I think they have same name and gets the last of them. Try put an alias to one of them Statistics as S1...

Actually the alias is third param, the first is model, I don't think so S1 will work.



46.7k

Try turning implicit joins off with the option enable_implicit_joins. You can disable it at the global level or the query level.