开发者

PHP / MySQL Join Query

开发者 https://www.devze.com 2023-01-30 18:40 出处:网络
does anyone know the best solution to join this query into 1 query rather than 2 as i cannot get it working you see.

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

精彩评论

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