表 1 - customer_kitchen_service_plans和資料https://prnt.sc/00_ip7uWiQuq
表 2 - kitchen_service_plans_linking和資料https://prnt.sc/e_GW64THTCFK
以上兩個是表,我想以這樣的方式加入,它應該回傳表 1 中的所有行和表 2 中的常見行
使用kitchen_service_plan_id表 1 和kitchen_service_plan_parent_id表 2中的列連接
當前查詢如下
select * from `customer_kitchen_service_plans` as `cksp`
left join `kitchen_service_plans_linking` as `kspl` on
`kspl`.`kitchen_service_plan_parent_id` =
`cksp`.`kitchen_service_plan_id`
where `cksp`.`status` = 'ACTIVE' and `cksp`.`customer_id` = 2
uj5u.com熱心網友回復:
您需要一個左外連接,它回傳第一個表中的所有行并從右側回傳匹配行。
select * from `customer_kitchen_service_plans` as cksp
left outer join `kitchen_service_plans_linking` as kspl on
kspl.`kitchen_service_plan_parent_id` =
cksp.`kitchen_service_plan_id`
where cksp.`status` = 'ACTIVE' and cksp.`customer_id` = 2
這是關于 MySQL 中的 Left Outer Join的討論
uj5u.com熱心網友回復:
看看有沒有幫助
SELECT * FROM customer_kitchen_service_plans
LEFT JOIN kitchen_service_plans_linking ON
customer_kitchen_service_plans.kitchen_service_plan_id=
kitchen_service_plans_linking.kitchen_service_plan_parent_id;
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/510805.html
