嗨,我正在尝试使用laravel中的join进行以下查询。
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
到目前为止我所做的事情:
$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();
在第二次加入“ banner_creatives.campaignId”时出错
提前致谢
最佳答案
您错过了一个联接。只需将其添加到其他
$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();