我有3桌食物,餐馆和类别 我想在这些之间加入。我有一个查询加入食物和类别:
> $Category = DB::table('food')->select('food.Food_id','food.FoodName','food.FoodImage','food.FoodType','categories.CategoryName')->join('categories','categories.Category_id','=','food.Category_id')->where('categories.CategoryName', '=','Breakfast')->get();
我想加入餐厅。我怎么能这样做? 我的表是:
食物:Food_id(PK)
FoodName
CATEGORY_ID(FK)
类别表是:
CATEGORY_ID(PK)
类别名称
餐厅餐桌是:
RES_ID
RES_NAME
Address_loc
Food_id(FK)
答案 0 :(得分:0)
$Category = DB::table('food')->select('food.Food_id','food.FoodName','food.FoodImage','food.FoodType','categories.CategoryName', 'restaurant.Res_Name')
->join('restaurant', 'restaurant.Food_id', '=', 'food.Food_id')
->join('categories','categories.Category_id','=','food.Category_id')
->where('categories.CategoryName', '=','Breakfast')->get();
您可以使用Food_id加入餐厅食物。
(不确定代码的语法是否正确,但它适合您的示例。可能必须更改餐馆的表名,因为您似乎在大小写之间切换)