joining multiple tables using laravel

Hi I am trying to do the following query using join in laravel.

select  advertisers.advertiserName,brands.brandName  
        ,campaigns.campaignName,banner_creatives.bannerName         
from vicinity_adman_dev.advertisers
     join vicinity_adman_dev.brands 
     join vicinity_adman_dev.campaigns
     join vicinity_adman_dev.banner_creatives

     on advertisers. advertiserId = brands.advertiserId
     where 
     banner_creatives.campaignId = campaigns.campaignId

What i DID so far:

  $campaigns =DB::table('brands')

 ->join('advertisers','brands.advertiserId' , '=','advertisers.advertiserId'               
                ->join('campaigns','banner_creatives.campaignId',
                        '=','campaigns.campaignId')  

  select('advertisers.advertiserName','brands.brandName','campaigns.campaignName','banner_creatives.bannerName')   
->get();

getting error on second join "banner_creatives.campaignId" thanks in advance

Answers


You missed one of your joins. Just add it to the others

$campaigns = DB::table('brands')
               ->join('advertisers', 'brands.advertiserId', '=', 'advertisers.advertiserId')
               ->join('campaigns', 'banner_creatives.campaignId', '=', 'campaigns.campaignId')
               ->join('banner_creatives', 'banner_creatives.bannerCreativeId', '=', 'other_table.bannerCreativeId')
               ->select(
                   'advertisers.advertiserName',
                   'brands.brandName',
                   'campaigns.campaignName',
                   'banner_creatives.bannerName'
               )
               ->get();

Need Your Help

Randomize content search web part results

search sharepoint-2013 web-parts

I am attempting to randomize search results from a content search web part on an o365 sharepoint farm.

How to pass a variable from View to Controller in ASP .NET

javascript html asp.net asp.net-mvc

I found similar questions to mine, but in all of those examples, the variable was part of the model. I am trying to pass a variable that is created in javascript, which is not part of the model.