KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Dashboard query ->leftJoin multiple conditions possible? #3392

Closed Marloes opened this topic on on Nov 21 - 5 comments

Marloes commented on Nov 21

Hi there,

How do I add multiple conditions to the leftJoin method:

Currently I see only one condition possible like:

->leftJoin("level", "settings.level_id","=","level.id")

But I would like to add more like a normal query with the "AND" condition: left join level as LVL ON LVL.level_id = A.id AND LVL.value = 3

How do I do such multiple conditions with the

->leftJoin ?

With kind regards, Marloes

Eugene commented on Nov 21

I think there is the answer in docs

DB::table('users')
    ->join('contacts', function ($join) {
        $join->on('users.id', '=', 'contacts.user_id')
                 ->where('contacts.user_id', '>', 5);
    })
Marloes commented on Nov 21

Hi Eugene,

Well that is not what I actually need :-) I need it in the Join itself and not in the where clause because it has a different function in the query. I still need it in the left join to speciffically downsize the left join results ... and not the overall (where).

With kind regards, Marloes

Sebastian Morales commented on Nov 22

I think the join documentation confirms Eugene's answer here:

https://www.koolreport.com/docs/querybuilder/overview/#joins-advanced-join-clauses

Pls try it and let us know if it returns results different from what you expect.

Eugene commented on Nov 22

Marloes,

I understand what confuses you. But pay your attention that the where in this case is inside the join and actually does not belong to the main query. In this case it is translated to the AND in the ON part of sql. :-) If you are not sure try to use toSQL() method to see the resulted sql query or debug.

Marloes commented on Nov 22

Thx Eugene (and Sebastian)! I've got it working now. I was searching in the 'wrong' places. Thx again!

With kind regards, Marloes

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

Dashboard