I am horrible with SQL and trying to get better at it, I have the following tables and want show only the types that are available, while counting the products in that category.
Table 1: Types
Type_Id | Name |
---|---|
1 | Candy |
2 | Chocolate Bar |
Table 2: Products
Product_Id | Name | Type_Id | AvailabilityId |
---|---|---|---|
1 | Chocolate Name 1 | 1 | 1 |
2 | Chcoolate Name 1 | 2 | 2 |
3 | Candy Name 1 | 2 | 2 |
Table 3: Availability
Availability_Id | Name |
---|---|
1 | Available |
2 | Reserved |
3 | Sol d |
Desired Result:
Type_Id | Name | TotalAvailable |
---|---|---|
1 | Candy | 1 |
2 | Chocolate | 2 |
Thanks in advance!
CodePudding user response:
You can use an inner query with inner join to achieve this. Here's a SQL fiddle: