james
james

Reputation: 7

PHP / MySQL Join Query

does anyone know the best solution to join this query into 1 query rather than 2 as i cannot get it working you see.

function fn_order_category_get_order_info($cat_id)
{
    $id1 = db_query("SELECT category_id FROM ?:products_categories WHERE product_id = $cat_id");
    $id2 = db_query("SELECT category FROM ?:category_descriptions WHERE category_id = $id1");
    return $id2;
}

Thanks in advance!

Upvotes: 0

Views: 246

Answers (1)

Try this:

SELECT 
    pc.category_id,
    cd.category 
FROM
    products_categories pc 
    LEFT JOIN
    category_descriptions cd 
    ON pc.category_id = cd.category_id 
WHERE product_id = $product_id ;

Upvotes: 2

Related Questions