# query with 3(4) tables.

**URL:** <https://www.phphelp.com/t/query-with-3-4-tables/16818>\
**Category:** MySQL database\
**Created:** [April 29, 2012, 2:34pm UTC](https://www.phphelp.com/t/query-with-3-4-tables/16818 "2012-04-29T14:34:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rob1](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/e495f1/32.png) [@Rob1](https://www.phphelp.com/u/Rob1)\
**Post date:** [April 29, 2012, 2:34pm UTC](https://www.phphelp.com/t/query-with-3-4-tables/16818/1 "2012-04-29T14:34:56Z")

</div>

Hi,

I’m struggling with 3 tables, i want to make a query en have to make two joins (if possible).

[table]  
[tr][td] (table 1) [/td][td] [/td][td] (table 2) [/td][td] [/td][td] (table 3) [/td][td] [/td][td] (table 4)[/td][/tr]  
[tr][td] Cat (table name) [/td][td] [/td][td] Cat\_Prod (table name) [/td][td] [/td][td] Prod (table name) [/td][td] [/td][td] Fab (table name) [/td][/tr]  
[tr][td] catagory [/td][td] [/td][td] id [/td][td]=== [/td][td] id [/td][td] [/td][td] name [/td][/tr]  
[tr][td] category\_id [/td][td] === [/td][td] category\_id [/td][td] [/td][td] manufacturer\_id [/td][td] === [/td][td] manufacturer\_id[/td][/tr]  
[/table]

I have to query on category\_id and need the fields category, some Prod fields, and ’ name ’ from Fab.

How do I get this?!?!!? :o

[php] $SQL\_statement = "SELECT \* FROM Cat\_Prod JOIN Prod on Cat\_Prod.product\_id = Prod.id WHERE category\_id = ‘$id’ AND Prod.status \>0 ORDER BY id ASC ";  
[/php]  
When I use this I can not diplay Fab.name or Cat.category?

The $id is coming from the url ($category\_id=$\_GET[‘id’] ; )

Is there someone who can help?

Thanks Rob.

---

<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 30, 2012, 9:30pm UTC](https://www.phphelp.com/t/query-with-3-4-tables/16818/2 "2012-04-30T21:30:38Z")

</div>

This topic was marked solved, without any replies. Rob, did you solve it yourself? Or do you still need help?

---

<div class="post-metadata">

**Author:** ![Rob1](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/e495f1/32.png) [@Rob1](https://www.phphelp.com/u/Rob1)\
**Post date:** [May 1, 2012, 6:05am UTC](https://www.phphelp.com/t/query-with-3-4-tables/16818/3 "2012-05-01T06:05:20Z")

</div>

Hello ErnieAlex,

After a good night rest and a bit of google I found out it isn’t so hard to do the trick.

First I tried UNION, this I don’t understand, :-[  
but a few JOINS did trick.  
Simpel and easy, thanks for the help (again) on this great forum.

Rob

---

<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:** [May 1, 2012, 6:35am UTC](https://www.phphelp.com/t/query-with-3-4-tables/16818/4 "2012-05-01T06:35:37Z")

</div>

Glad you solved it. Always a nice warm fuzzy feeling to solve a programming puzzle!

CYA in the bitstream…
