X
X
xlo2402020-04-29 15:21:14
MySQL
xlo240, 2020-04-29 15:21:14

How to join multiple tables on one field?

There is a working request. It will append to main_tbl2 an additional table dopstr_tbl2 with a comparison field marker_dop

SELECT `main_tbl2`.*, `dopstr_tbl2`.* FROM `main_tbl2` 
LEFT JOIN `dopstr_tbl2` ON `main_tbl2`.`alias` = `dopstr_tbl2`.`marker_dop`

How to write a query so that the same comparison also goes through the tables dopstr_tbl3 dopstr_tbl4 dopstr_tbl5 ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
irishmann, 2020-04-29
@xlo240

The same as with the dopstr_tbl2 table.

SELECT 
     `main_tbl2`.*,
     `dopstr_tbl2`.*, 
     `dopstr_tbl3`.* 
FROM `main_tbl2` 
     LEFT JOIN `dopstr_tbl2` ON `main_tbl2`.`alias` = `dopstr_tbl2`.`marker_dop`
     LEFT JOIN `dopstr_tbl3` ON `main_tbl2`.`alias` = `dopstr_tbl3`.`marker_dop`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question