How to build a SQL query to 2 other tables?

Hello!
Can't figure out how to build a query to 2ум tables properly to output the required data.

There is a table banks with columns id_bank and bank_name
the table products with columns id_product, id_bank and product_name

In the table matrix has columns id_priority, product1, product2, product3
in columns product1 product3 recorded id of the desired products.

You want to display in the query to get this way:
20171214-12h-24kb.jpg
June 10th 19 at 15:12
2 answers
June 10th 19 at 15:14
Solution
SELECT 
m.id_priority, b1.bank_name, p1.product_name, b2.bank_name, p2.product_name, b3.bank_name, p3.product_name
FROM matrix m 
INNER JOIN products p1 ON m.product1 = p1.id_product 
INNER JOIN products p2 ON m.product2 = p2.id_product 
INNER JOIN products p3 ON m.product3 = p3.id_product 
INNER JOIN banks b1 ON p1.id_bank = b1.id_bank
Banks INNER JOIN b2 ON p2.id_bank = b2.id_bank
INNER JOIN banks b3 ON p3.id_bank = b3.id_bank
ORDER BY m.id_priority
June 10th 19 at 15:16
there are columns id_priority, product1, product2, product3

And when the 100 products - will create 100 columns? Make a normal table.
The table matrix is fixed priority product at the date of this Appendix. The maximum number of products = 10. - jalen_Strosin89 commented on June 10th 19 at 15:19

Find more questions by tags SQLMySQL