【发布时间】:2016-04-14 17:16:47
【问题描述】:
我有 3 个表,1 个是父表和 2 个子表。 第一个表包含所有订单号,其他 2 个子表包含订单号的订单详细信息
示例 表 Order_master
order_id | order_date | order_status
-------------------------------------
1 | 20-10-15 | pending
------------------------------------
2 | 10-11-15 | closed
------------------------------------
3 | 15-11-15 | closed
------------------------------------
4 | 25-12-15 | pending
------------------------------------
5 | 27-12-15 | closed
------------------------------------
子表order_detail
-------------------------------------
id | order_id | client_name
-------------------------------------
1 | 1 | Abc company
------------------------------------
2 | 3 | Test company
子表order_detail_cc
-------------------------------------
id | order_id | client_name
-------------------------------------
1 | 2 | XYZ company
------------------------------------
2 | 4 | A2 company
------------------------------------
3 | 5 | B2 company
------------------------------------
现在我想得到结果
-------------------------------------
order_id | order_date | client_name
-------------------------------------
1 | 20-10-15 | Abc company
------------------------------------
2 | 10-11-15 | XYZ company
------------------------------------
3 | 15-11-15 | Test company
------------------------------------
4 | 25-12-15 | A2 company
------------------------------------
5 | 27-12-15 | B2 company
------------------------------------
请帮忙
【问题讨论】:
-
如果一个订单的details或details_cc中有很多条目怎么办?如果一个订单的两个表中都有条目怎么办?
-
你尝试过什么样的查询?
标签: mysql database join inner-join