Distinct delete duplicate row

zhaozj2021-02-12  145

Distinct

After processing the selected list, the generated table can delete the repeated row. We can write DISTINCT keywords directly to achieve this purpose:

Select Distinct SELECT_LIST ...

(If you don't have to Distinct you can use all to select the default behavior of all rows.)

Obviously, if there is at least one column in the two lines, we think it is independent. NULL is the same in this consideration.

In addition, we can also use any expressions to determine what line can be independent:

Select Distinct On (Expression [, Expression ...] Select_List ...

Here Expression is an arbitrary value expression that is calculated for all rows. If the value of this expression calculated in a row is the same, then we believe that they are repeated and therefore only the first line remains in the output. Note that the "first line" of a collection here is unpredictable unless you are sequenced on a sufficiently field to ensure that the order in which the Distinct filter is reached is unique. (Distinct ON processing is behind the order of order by.)

The Distinct ON clause is not part of the SQL standard, sometimes someone thinks it is a bad style because it is not determined. If you use a selected group by and a child in from from, then we can avoid using this configuration, but usually it is a more convenient candidate method.

转载请注明原文地址:https://www.9cbs.com/read-6832.html

New Post(0)