如何加入两个SQL查询

时间:2017-01-25 08:05:43

标签: php mysql join

我有5张桌子

标题

ID_title(pk)| nameTitle
-----------------------------
 t1     | Distance Examination

列表

ID_list(pk)| nameList   |ID_unit |ID_title
-----------------------------------------
 l1    | Appearance | u1     | t1

单元

ID_unit(pk)| nameUnit
-----------------------------
 u1    | beats per min(bpm)

选择

ID_choice(pk)| nameChoice
-----------------------------
 c1    | Thoracoabdomen

list_choice

ID_list(pk)| ID_choice (pk) |Order_LiCh(pk)
--------------------------------------------
 l1    | c1 |1

我不知道如何创建这样的结果:

ID_title| nameTitle    |ID_list| nameList   |ID_unit |nameUnit          |ID_choice| nameChoice|Order_LiCh
--------------------------------------------------------------------------------------------------------------
t1      | Milk Quality |l1     | Appearance | u1     |beats per min(bpm)| c1      |Thoracoabdomen||1

我有两个SQL查询 第一个查询:

SELECT title.ID_title
, title.nameTitle
, list.ID_list
, list.nameList
, list.ID_unit
, list.ID_title
, unit.ID_unit
, unit.nameUnit

FROM list
INNER JOIN title ON list.ID_title = title.ID_title 
INNER JOIN unit ON list.ID_unit = unit.ID_unit

第二个问题:

 SELECT choice.ID_choice
, choice.nameChoice
, list_choice.ID_choice
, list_choice.ID_list
, list_choice.order_LiCh
, list.ID_list
, list.nameList
, list.ID_unit
, list.ID_title
FROM list_choice
INNER JOIN choice ON choice.ID_choice = list_choice.ID_choice
INNER JOIN list  ON list.ID_list = list_choice.ID_list

如果您有任何建议,请告诉我。 谢谢你的帮助。

0 个答案:

没有答案