开发者

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_inf开发者_高级运维o($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!


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 ;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜