KoolReport's Forum

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

Multi-level Joins #271

Open David Willink opened this topic on on May 8, 2018 - 1 comments

David Willink commented on May 8, 2018

Hello,

How do you do a multi-level join on tables that are not linked to the table specified in ->query ?

            select distinct
                GBAT.GroupBatchID, 
                AIRL.Name as AirlineName,
                GBAT.CreateDate,
                GBAT.CreateTime,
                GBAT.BatchNote,
                GBAT.GroupType
            from 
                dba.groupbatches GBAT, 
                dba.HotelTranDetail HTRD, 
                dba.HotelTrans HTRN, 
                dba.BATCHES BAT,
                dba.AIRLINES AIRL
            where
                HTRD.PostingGBatchID = GBAT.GroupBatchID and
                HTRN.HTRANSID = HTRD.HTransID and
                BAT.BatchID = HTRN.BATCHID AND  
                AIRL.AirlineID = BAT.AIRLINEID and .    <<----
                GBAT.CreateDate >= '{$d}' AND 
                GBAT.GroupType = {$t}

My start...

        $this->src('mysource')->query(MYSQL::type(
            DB::table('HotelTranDetail')
            ->join('GroupBatches', 'PostingGBatchID', '=', 'GroupBatchID')
            ->join('HotelTrans', 'HTransID', '=', 'HTransID')
            ->join('Batches', 'BatchID', '=', 'BatchID')
            ->join('Airlines', 'Batches.BatchID', '=', 'BatchID') .      <<---   Airlines is related to Batches, not HotelTranDetail
            ....

Thank you.

David

KoolReport commented on May 9, 2018

Then you do as following:

->join('GroupBatches', 'HotelTranDetail.PostingGBatchID', '=', 'GroupBatches.GroupBatchID')
->join('HotelTrans', 'HotelTrans.HTransID', '=', 'HotelTranDetail.HTransID')
->join('Batches', 'Batches.BatchID', '=', 'HotelTrans.BatchID')
->join('Airlines', 'Batches.BatchID', '=', 'Airlines.BatchID')

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
None yet

None