# How do i cross join , Inner join and Group tables

**URL:** <https://www.phphelp.com/t/how-do-i-cross-join-inner-join-and-group-tables/33370>\
**Category:** MySQL database\
**Created:** [April 18, 2021, 3:08pm UTC](https://www.phphelp.com/t/how-do-i-cross-join-inner-join-and-group-tables/33370 "2021-04-18T15:08:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sashavalentina](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@sashavalentina](https://www.phphelp.com/u/sashavalentina)\
**Post date:** [April 18, 2021, 3:08pm UTC](https://www.phphelp.com/t/how-do-i-cross-join-inner-join-and-group-tables/33370/1 "2021-04-18T15:08:10Z")

</div>

I have 3 tables which are `order tables` , `product tables` and `category_tables` .

 ![image](https://www.phphelp.com/uploads/default/original/2X/7/7b82071ac2eb011571f75fbe72f636939fc74f18.png)  
I want to get the result of the category `Meat` only from the `order_tables` by cross joining it with the `product tables` and the `category_tables` . But why do i always get the result of the first product with the category i selected. This is the sql i use to select the Meat category

```auto
SELECT * FROM (
(SELECT * FROM order_table) as yw1
INNER JOIN 
(SELECT * FROM products) as yw2 ON yw1.product_id = yw2.id
CROSS JOIN 
(SELECT * FROM category) as yw5 ON yw2.product_category = yw5.id)
GROUP BY category = "Meat"

```

For example, i selected the Meat category it will show the result of

| id | order\_id | product\_id | product\_name | id | category\_name |  
| 1 | 10001 | 1 | carrot | 1 | Tubers |  
| 4 | 10004 | 4 | Beef | 4 | Meat |

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [April 19, 2021, 5:36pm UTC](https://www.phphelp.com/t/how-do-i-cross-join-inner-join-and-group-tables/33370/2 "2021-04-19T17:36:41Z")

</div>

First, JOIN, INNER JOIN and CROSS JOIN are exactly the same thing. What do you want to get out?

> [@](#):
>
> SELECT \* FROM order\_table as yw1  
> JOIN products as yw2  
> ON yw1.product\_id = yw2.id  
> JOIN category as yw5  
> ON yw2.product\_category = yw5.id  
> GROUP BY yw5.category\_name = “Meat”

This might work, but, we would need to know what you want out of it. Your query SELECTs data and you join the data, but, I think you need to join the tables. Also not sure you can GROUP-BY one category, you might need to change that section to use a WHERE instead. Again, it depends on what you want out of the query. If you want to total ALL orders that contain “MEAT”, then you group them and use a WHERE to select only the “MEAT” values. If you want a list of all “MEAT” orders, you drop the group and just use the WHERE… Hope this helps!
