Simplifying my problem:
I have 3 tables.
Expand|Select|Wrap|Line Numbers
- user_master
- ----------
- int user_id
- char user_name
- product_master
- ----------
- int product_id
- char product_name
- int product_category
- user_product
- ----------
- int user_id
- int product_id
I need to ouput for each of them the number of products of each
category
For example:
Expand|Select|Wrap|Line Numbers
- User | Chair | Table | Desk
- ----------+----------+----------+-----------
- Dupont | 2 | 3 | 1
- Dupuy | 1 | 0 | 3
- Martin | 0 | 1 | 2
Expand|Select|Wrap|Line Numbers
- SELECT
- usr.user_name 'Nom',
- count(up1.product_id) 'Chaise',
- count(up2.product_id) 'Table',
- count(up3.product_id) 'Bureau',
- pr.product_name 'Produit'
- FROM
- user_master usr
- NATURAL LEFT JOIN user_product up1
- NATURAL LEFT JOIN user_product up2
- NATURAL LEFT JOIN user_product up3
- NATURAL LEFT JOIN product_master pr
- WHERE
- up1.product_category = 1 AND
- up2.product_category = 2 AND
- up3.product_category = 3
- GROUP BY Nom
- ORDER BY Nom
result.
In fact, I don't understand the principal of the JOIN but I mainly
don't understand his results.
Thx in advance.