SQL Query over three different tables
Posted
by choise
on Stack Overflow
See other posts from Stack Overflow
or by choise
Published on 2010-05-17T10:40:15Z
Indexed on
2010/05/17
10:50 UTC
Read the original article
Hit count: 224
i got three tables
CATS
id name
------------------------------
1 category1
2 category2
3 category3
4 category4
PRODUCT
id name
------------------------------
1 product1
2 product2
ZW-CAT-PRODUCT
id_cats id_product
------------------------------
1 1
3 1
4 2
now i want to get my products and their categories
product1 => category1,category3
product2 => category4
is there a way to get this array (or object or something) with one mysql query? i tried a bit with JOINS, but it seems thats this is not exactly what i need, or?
currently i'm using 3 querys (i think thats too much).
any suggestions?
© Stack Overflow or respective owner