Oracle 中的 Unique 与 Distinct 关键字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/174912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unique vs Distinct keyword in Oracle
提问by Michael OShea
I am a bit confused about the uses of these words. I have a table with he following columns: SITE, LAT, LONG, NAME, ......
我对这些词的用法有点困惑。我有一个包含以下列的表格:SITE、LAT、LONG、NAME、......
I want results with unique (or is it distinct) LAT, LONG. How do I achieve this?
我想要具有独特(或不同)LAT、LONG 的结果。我如何实现这一目标?
回答by Michael OShea
select unique colA, colB from atable
select distinct colA, colB from atable
In this context, unique and distinct mean the same thing.
在这种情况下,独特和独特意味着同一件事。
Distinct however is ANSI standard, whereas unique is not.
然而,ANSI 标准是 Distinct,而 unique 不是。
Please note that unique has many other meanings when used in other area's ie index creation etc.
请注意,unique 在其他领域的 ie 索引创建等中使用时还有许多其他含义。
回答by Joe Moraca
I always like to see a count of how many of each unique item there is so I would:
我总是喜欢查看每个独特项目的数量,所以我会:
select lat,long, count(lat) from table group by lat,long but thats just me
从表组中选择 lat,long, count(lat) by lat,long 但那只是我
回答by skaffman
UNIQUE is used for defining contraints on the data that can be stored in the table.
UNIQUE 用于定义对可以存储在表中的数据的约束。
DISTINCT is used in queries to remove duplicates from the result set, without affecting the underlying table data.
DISTINCT 在查询中用于从结果集中删除重复项,而不影响基础表数据。
回答by skaffman
AFAIR both mean the same. To get unique vel distinct LAT & LONG from your table just do:
AFAIR 两者的意思相同。要从您的表中获得独特的 vel 不同的 LAT 和 LONG,只需执行以下操作:
SELECT DISTINCT LAT, LONG FROM table;
SELECT DISTINCT LAT, LONG FROM table;