2016-04-08 25 views
-3

我有三個表稱爲table1,table2和table3,每個表都包含一個主鍵。所有三個表共同的產品表。其中包含三個表的所有主鍵。不,我想顯示產品詳細信息作爲嵌套數組我怎麼能做到這一點?如何在mysql中使用連接顯示所有產品

table1 contains: 
name 
id 

table2 contains: 
name 
id 

table3 contains: 
name 
id 
products table 
id 
name 
description 
table1_id 
table2_id 
table3_id 

my output like 
table1 
{ 
name 
    { products.name, products.description }, 
    { products.name, products.description } 
} 
    table2 
    name { products.name, products.description }, 
    { products.name, products.description } 
    } 
    table3 
    { 
    name {products.name, products.description}, 
    { products.name, products.description } 
+2

的可能的複製[選擇\ * FROM多個表。 MySQL](http://stackoverflow.com/questions/12890071/select-from-multiple-tables-mysql) – Tom

+0

可以請你詳細說明你的答案 –

+0

我說這是一個可能的重複包含你正在尋找的答案。 – Tom

回答

0

使用下面的SQL查詢與多個左加入,我希望這會爲你工作..

select * from products 
left join table1 
on table1.id = products.table1_id 
left join table2 
on table2.id = products.table2_id 
left join table1 
on table3.id = products.table3_id 
相關問題