laravel join關(guān)聯(lián)查詢代碼實(shí)例
laravel join關(guān)聯(lián)查詢
1、兩表關(guān)聯(lián)
$fbaInventoryTb = (new \App\Model\Amz\Fba\InventoryReport)->getTable();
$productTb = (new \App\Model\Amz\Product)->getTable();
$twInventoryTb = (new \App\Model\TWUsa\TwusaInventory)->getTable();
$qry = \DB::table($fbaInventoryTb);
$qry->select($fbaInventoryTb.'.*')
->where($fbaInventoryTb.'.ec_id',1)
->leftjoin($productTb, $productTb.'.sku', '=', $fbaInventoryTb.'.sku')
->addSelect($productTb.'.id as goods_id',$productTb.'.sku as mfn', $productTb.'.ec_id as pro_ec_id');
// ->where($productTb.'.ec_id',1); //不應(yīng)該在此處排除 product 表的ec_id
// return $qry->toSql();
$res = $qry->get()->whereIn('pro_ec_id',[1, null] );//leftJion 最后排除不符合條件的
2、三表關(guān)聯(lián)
$qry = \DB::table($twInventoryTb);
$qry->select($twInventoryTb.'.*')
->leftjoin($fbaInventoryTb, $fbaInventoryTb.'.fnsku', '=', $twInventoryTb.'.product_sn')
->addSelect($fbaInventoryTb.'.ec_id')
->where($fbaInventoryTb.'.ec_id',1);
$qry->LeftJoin($productTb, $productTb.'.sku', '=', $fbaInventoryTb.'.sku')
// ->where($productTb.'.ec_id',1)
->addSelect($productTb.'.id as goods_id', $productTb.'.sku as mfn', $productTb.'.ec_id as pro_ec_id');
$res = $qry->get()->whereIn('pro_ec_id', [1, null]);
到此這篇關(guān)于laravel join 關(guān)聯(lián)查詢代碼實(shí)例的文章就介紹到這了,更多相關(guān)laravel join 關(guān)聯(lián)查詢內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Laravel重定向,a鏈接跳轉(zhuǎn),控制器跳轉(zhuǎn)示例
今天小編就為大家分享一篇Laravel重定向,a鏈接跳轉(zhuǎn),控制器跳轉(zhuǎn)示例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10
PHP實(shí)現(xiàn)文件上傳與下載實(shí)例與總結(jié)
這篇文章主要介紹了PHP實(shí)現(xiàn)文件上傳與下載實(shí)例與總結(jié)的相關(guān)資料,需要的朋友可以參考下2016-03-03
PHP FATAL ERROR: CALL TO UNDEFINED FUNCTION BCMUL()解決辦法
這篇文章主要介紹了PHP FATAL ERROR: CALL TO UNDEFINED FUNCTION BCMUL()解決辦法,需要的朋友可以參考下2014-05-05
Symfony2框架創(chuàng)建項(xiàng)目與模板設(shè)置實(shí)例詳解
這篇文章主要介紹了Symfony2框架創(chuàng)建項(xiàng)目與模板設(shè)置的方法,結(jié)合實(shí)例形式詳細(xì)分析了Symfony2框架的具體步驟與詳細(xì)實(shí)現(xiàn)代碼,需要的朋友可以參考下2016-03-03
php中對內(nèi)置函數(shù)json_encode和json_decode的異常處理
這篇文章主要介紹了php中對內(nèi)置函數(shù)json_encode和json_decode的異常處理,本篇文章通過定義描述和列舉表格以及最后代碼的展示,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07
基于thinkphp6.0的success、error實(shí)現(xiàn)方法
這篇文章主要介紹了基于thinkphp6.0的success、error實(shí)現(xiàn)方法,本文分步驟給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-11-11
laravel Validator ajax返回錯(cuò)誤信息的方法
今天小編就為大家分享一篇laravel Validator ajax返回錯(cuò)誤信息的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09

