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

MySQL JOIN statement cross join?

mysql sql join

I'm not good with the old JOIN statements and looking for a little friendly help. I have two tables, lets say table Employee:

Flask flash and redirect - shows response in devtools but no pageload

python html ajax flash flask

New to flask here ... my problem is that I'm trying to check if a response is empty, and if so flash a message. With the below code, I can see that the redirect goes through and the subsequent GET

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.