473,396 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Join - 3 tables - products categories

Hello

Simplifying my problem:
I have 3 tables.

Expand|Select|Wrap|Line Numbers
  1. user_master
  2. ----------
  3. int    user_id
  4. char   user_name
  5.  
  6. product_master
  7. ----------
  8. int    product_id
  9. char   product_name
  10. int    product_category
  11.  
  12. user_product
  13. ----------
  14. int    user_id
  15. int    product_id
Of course the users can own multiple products
I need to ouput for each of them the number of products of each
category
For example:

Expand|Select|Wrap|Line Numbers
  1. User      | Chair    | Table    | Desk
  2. ----------+----------+----------+-----------
  3. Dupont    |        2 |        3 |        1
  4. Dupuy     |        1 |        0 |        3
  5. Martin    |        0 |        1 |        2
I'm on this way:

Expand|Select|Wrap|Line Numbers
  1. SELECT
  2. usr.user_name 'Nom',
  3. count(up1.product_id) 'Chaise',
  4. count(up2.product_id) 'Table',
  5. count(up3.product_id) 'Bureau',
  6. pr.product_name 'Produit'
  7. FROM
  8. user_master usr
  9. NATURAL LEFT JOIN user_product up1
  10. NATURAL LEFT JOIN user_product up2
  11. NATURAL LEFT JOIN user_product up3
  12. NATURAL LEFT JOIN product_master pr
  13. WHERE
  14. up1.product_category = 1 AND
  15. up2.product_category = 2 AND
  16. up3.product_category = 3
  17. GROUP BY Nom
  18. ORDER BY Nom
That doesn't seems to be complex, but this query gives me an empty
result.
In fact, I don't understand the principal of the JOIN but I mainly
don't understand his results.

Thx in advance.
Jul 20 '05 #1
0 1408

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ralph Guzman | last post by:
TASK: I have to generate a report with all categories, subcategories and products in database. PROBLEM: I want to write one query that will return: 1. category 2. subcategory: determined by...
3
by: sks | last post by:
I have a Product table, a Categories table and a join table that contains product to category mappings (each product can be in many categories) CREATE TABLE categories ( id bigint(20) unsigned...
14
by: Craig Hoskin | last post by:
Hi everyone Have a problem I would areally appreciate help with. I have 3 tables in a standard format for a Bookshop, eg Products Categories Categories_Products the latter allowing me to...
2
by: terence.parker | last post by:
I am often faced with the dilemma of whether to use a JOIN query across three tables in order to grab a bunch of results - or whether to create another table to represent what I want. The latter is...
23
by: Brian | last post by:
Hello All - I am wondering if anyone has any thoughts on which is better from a performance perspective: a nested Select statement or an Inner Join. For example, I could do either of the...
4
by: Steve Klett | last post by:
(I posted this in ADO group, but I think this group will be better) Hi- I need to develop an FAQ section for our website. We would like to break up the FAQ by products, then categories with...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
5
by: john7 | last post by:
I have three tables one for categories, one for products1 and another for products2. I am using PHP and MySQL. so for example I categories categoryid name 1 programming 2 databases 3 ...
6
by: jackal_on_work | last post by:
Hi Faculties, I have two queries which give me the same output. -- Query 1 SELECT prod.name, cat.name FROM products prod INNER JOIN categories cat ON prod.category_id = cat.id WHERE cat.id...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.