Please help make a request for the following situation: alt text

The case when the server has a separate cabinet for switches and a separate for patch panels. When the circuit was linear and there was a condition that everything is in the same cabinet, I just did it through LEFT JOIN :

 SELECT boxs.box, switchs.switch, path_panels.path_panel FROM info LEFT path_panels ON info.id_patch_panels = path_panels.id_patch_panels LEFT JOIN switchs ON info.id_switchs = switchs.id_switchs LEFT JOIN boxs ON info.id_boxs = boxs.id_boxs 

Now I have added the id_boxs2 column to info and I don’t know how to get the output in the grid in the following order: Шкаф, Коммут., Шкаф2, Патч-панель . It is also not possible to do linearly.

  • And what will id_box2 be associated with and why is this field? - Timenzzo
  • With boxs.id_box, this field will turn to the list of cabinets a second time and get Cabinet2 for patch panels. - Mr_Lambert_13

2 answers 2

Maybe I didn’t understand what, if anything, but then you need to use pseudonyms to turn to the boxs table a second time.

 SELECT b1.box, switchs.switch, b2.box, path_panels.path_panel FROM info LEFT path_panels ON info.id_patch_panels = path_panels.id_patch_panels LEFT JOIN switchs ON info.id_switchs = switchs.id_switchs LEFT JOIN boxs b1 ON info.id_boxs = b1.id_boxs LEFT JOIN boxs b2 ON info.id_boxs2 = b2.id_boxs 
  • Just as I didn’t think. Thank you very much. - Mr_Lambert_13

for good - the base must be redesigned

 SELECT b.box, b2.box, s.switch, p.path_panel FROM info i LEFT OUTER JOIN path_panels p ON p.id_patch_panels = i.id_patch_panels LEFT OUTER JOIN switchs s ON s.id_switchs = i.id_switchs LEFT OUTER JOIN boxs b ON b.id_boxs = i.id_boxs LEFT OUTER JOIN boxs b2 ON n2.id_boxs = i.id_boxs2