[英]How to get data from two API calls, merge them and display them in a table with my other data?
[英]Given two SELECT statements, how to merge them to get one result minus the other?
我想从wantedIDs
删除UNwantedIDs
,如何进行子查询并得到一个结果?
这是我的UNwantedIDs
查询:
SELECT
GROUP_CONCAT(DISTINCT `recipe_ingredient`.`recipeId` ORDER BY `recipe_ingredient`.`recipeId` ASC) UNwantedIDs
FROM `recipe_ingredient`
WHERE `recipe_ingredient`.`ingredientId`
IN(SELECT `ingredient`.`ingredientId` AS unlinkIng
FROM `ingredient`
WHERE `ingredient`.`ingredientId` IN(1) or `ingredient`.`linkIngredientPerent` IN(1))
ORDER BY `recipeId` ASC
http://sqlfiddle.com/#!2/84f00/5
这是我的wantedIDs
查询:
SELECT
GROUP_CONCAT(DISTINCT `recipe_ingredient`.`recipeId` ORDER BY `recipe_ingredient`.`recipeId` ASC) wantedIDs
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
http://sqlfiddle.com/#!2/84f00/4
结果ID如:
2,3,7,8,11,21,24,36,37,41,67,70,75,80,83,99,108
我有这个:
SELECT
GROUP_CONCAT(
DISTINCT `recipe_ingredient`.`recipeId`
ORDER BY `recipe_ingredient`.`recipeId` ASC
) wantedIDs
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)
)
)
AND `recipe_ingredient`.`recipeId` NOT IN (
SELECT
`recipe_ingredient`.`recipeId`
FROM `recipe_ingredient`
WHERE `recipe_ingredient`.`ingredientId`
IN (SELECT `ingredient`.`ingredientId` AS unlinkIng
FROM `ingredient`
WHERE `ingredient`.`ingredientId` IN(1) OR
`ingredient`.`linkIngredientPerent` IN(1)
)
)
ORDER BY `recipeId` ASC
这是用于合并两个查询的NOT IN
的结果。 目前速度很慢,可能是因为您需要添加一些索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.