获取重复项真的是糟糕的查询还是糟糕的数据库设计?

Get duplicates really is it a bad query or bad database design?

I have read this article

在第二段中这样说:

"The fact that the resultset has duplicates is frequently (though not always) the result of a poor database design, an ineffective query, or both".

以后用Adventures数据库做例子,估计设计的不错

嗯,我的疑惑是这种情况。我必须有表格、人员和订单,我想让所有至少有一个总计 >= 200 美元的订单的人。我会使用这个查询:

Select Persons.* from Persons, Orders where
Orders.IDPerson = Persons.IDPerson
and Orders.Total >= 200;

在这种情况下,我可以得到很多次同一个人,因为有不止一个订单,总数是 200 或更多。真的,我希望每个人在结果中出现一次,所以这个查询是不是一个糟糕的查询,因为我可以多次得到同一个人?

另一个选项是这个查询:

select * from Person where
IDPerson IN(select IDPerson from Orders where total >= 200);

在这种情况下,我每个人只得到一次,虽然这个人有一个以上的订单总数 >= 200。但是在主查询中使用子查询来避免重复是个好主意吗?

在这种情况下,Persons and orders,我猜数据库设计的还不错,因为我不知道设计这个模型我还有其他的选择,而且我猜的查询很简单,但是我怀疑在这种情况下是否得到重复项是错误查询的标志。

总而言之,在这种情况下获取重复是一个错误的查询吗?

谢谢。

我认为第一个查询这样不好。获取重复项似乎没有用,您稍后需要使用 DISTINCT 删除这些重复项。

带有子查询的秒查询在上下文中似乎更有用(也许有时使用 "exists" 而不是 "in" 更有意义)。

SQL Server IN vs. EXISTS Performance

这样的查询也是可以的:

select * 
from Person
join
(
    select IDPerson
    from Orders 
    where total >= 200  
) PersonsWithMoreThan200Total
on Person.IDPerson = PersonsWithMoreThan200Total.IDPerson