替代方式mysql在程序中嵌套查询

时间:2014-11-14 14:52:17

标签: mysql stored-procedures nested-query

有关程序中mysql嵌套查询的任何建议吗?

CREATE DEFINER=`root`@`%` PROCEDURE `GET_PLACE_PARENT_CATEGORY`(IN paramCategoryId INT)
BEGIN
    SELECT pc.place_parent_category_id, (SELECT pcc.place_category FROM place_category  pcc WHERE pcc.place_category_id = pc.place_parent_category_id )
FROM place_category pc WHERE pc.place_category_id = paramCategoryId;
END

1 个答案:

答案 0 :(得分:0)

您的嵌套查询位于同一个表中。你确定这是对的吗? 我相信你想在2个表之间进行简单的连接。这样的事情可能是:

SELECT pc.place_parent_category_id,pcc.place_category
来自place_category pc 在pcc.place_category_id = pc.place_parent_category_id上将la连接place_parent_category作为pcc 在哪里pc.place_parent_category_id = paramCategoryId;