The use of the keyword distinct in the oracle database

distinct means unique, which is a keyword used to remove duplicate query results; different usage conditions have different effects.

Basic usage: select distinct num (distinct fields) from table; here the distinct query comes out The content is to query the result according to whether the num is unique. If the num is the same two query results, then one of the results will be displayed; as shown in the following figure:

Before the


query: After the query:







If in the query statement, add both fields with To modify with distinct, this has to be explained by the set in mathematics, which means that both fields are the same query result, and the result is displayed one! (Similarly, if distinct modifies multiple fields at the same time, a similar principle) is shown in the following figure:

Before query:



After query:


Visible, after executing distinct to modify num and name fields, 3, 4, 5, and 6 rows of data The num and name are equivalent, 3 rows and 4 rows take one of them, 5 and 6 rows go to one of them, and finally a 4 row result set!


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326466642&siteId=291194637