从Access SQL表中查找重复的行

时间:2014-06-24 13:39:32

标签: sql select duplicates

我有一个名为POTION_INGREDIENTS的表的简单数据库。

此表包含POTION_CODE,INGREDIENTE_CODE和QUANTITY字段以创建配方。

我想为POTION_CODE等于C1和C2的药水找到常见的INGREDIENTES。

我正在尝试以下查询,但这不起作用:

SELECT
INGREDIENT

FROM 
POTION_INGREDIENTS

WHERE
POTION_CODE='C1' OR
POTION_CODE='C2'

HAVING COUNT(INGREDIENTE) > '1'

此致

2 个答案:

答案 0 :(得分:0)

尝试:

SELECT INGREDIENT
FROM   POTION_INGREDIENTS
WHERE  POTION_CODE IN ('C1','C2')
GROUP  BY Ingredient
HAVING COUNT(INGREDIENT) > 1

http://www.w3schools.com/sql/sql_having.asp

答案 1 :(得分:0)

尝试使用

select    ingredient,
          count(ingredient)
from      potion_ingredients
where     potion_code = 'C1'
          or potion_code = 'C2'
group by  ingredient
having    count(ingredient) > 1