当我运行此查询结果越来越
SELECT
GROUP_CONCAT(`recipe_ingredient`.`recipeId`)
FROM `recipe_ingredient`
WHERE `recipe_ingredient`.`ingredientId`
IN(4,11,33,36,54,117,135,136,178,185,218,312,348,378)
ORDER BY `recipeId` ASC
但是我想从其他表获取以上查询“ IN”值,所以我正在创建新查询,但没有得到结果
请参阅以下新查询
SELECT
GROUP_CONCAT(`recipe_ingredient`.`recipeId`)
FROM `recipe_ingredient`
WHERE `recipe_ingredient`.`ingredientId`
IN(
SELECT
GROUP_CONCAT(`ingredient`.`ingredientId`
ORDER BY `ingredient`.`ingredientId` ASC ) AS unlinkIng
FROM `ingredient`
WHERE `ingredient`.`ingredientId` IN(4,178) or `ingredient`.`linkIngredientPerent` IN(4,178)
)
ORDER BY `recipeId` ASC
最佳答案
从子查询中删除GROUP_CONCAT
:
SELECT
GROUP_CONCAT(`recipe_ingredient`.`recipeId`)
FROM
`recipe_ingredient`
WHERE
`recipe_ingredient`.`ingredientId` IN (SELECT `ingredient`.`ingredientId` AS unlinkIng
FROM `ingredient`
WHERE `ingredient`.`ingredientId` IN (4, 178)
OR `ingredient`.`linkIngredientPerent` IN (4, 178))
ORDER BY
`recipeId` ASC