时间:2021-07-01 10:21:17 帮助过:22人阅读
SELECT
columns. This can sometimes lead to unexpected results when used in conjunction with distinct()
. If you order by fields from a related model, those fields will be added to the selected columns and they may make otherwise duplicate rows appear to be distinct. Since the extra columns don’t appear in the returned results (they are only there to support ordering), it sometimes looks like non-distinct results are being returned.
Similarly, if you use a values()
query to restrict the columns selected, the columns used in any order_by()
(or default model ordering) will still be involved and may affect uniqueness of the results.
The moral here is that if you are using distinct()
be careful about ordering by related models. Similarly, when using distinct()
and values()
together, be careful when ordering by fields not in the values()
call.
关于Django中的数据库操作API之distinct去重的一个误传
标签:duplicate app order lin block mod django distinct web