How can I write a three-table join SQL statement?

Asked 1 years ago, Updated 1 years ago, 109 views

The table structure is shown below.

What I want to show you is to show the materials that belong to the product in the product list.

Product 1 | (Material 1, Material 2)

Product 2 | (Material 1, Material 3)

Product 3 | (Material 2, Material 3, Material 4)

Product 4 | (Material 1, Material 2, Material 3)

I have to join three tables, but I can't think of what to do.

Is it possible only with sql?

sql querying

2022-09-22 12:54

1 Answers

SELECT *
FROM products
JOIN bill_of_material ON products.unit_id = bill_of_material.unit_id
JOIN materials ON bill_of_material.material_id = materials.material_id

You can do it like this.

Please keep that in mind: https://www.w3schools.com/sql/sql_join_inner.asp


2022-09-22 12:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.