Unique vs Distinct keyword in Oracle

前端 未结 4 1766
渐次进展
渐次进展 2021-01-18 17:54

I am a bit confused about the uses of these words. I have a table with he following columns: SITE, LAT, LONG, NAME, ......

I want results with unique (or is it disti

相关标签:
4条回答
  • 2021-01-18 18:20

    UNIQUE is used for defining contraints on the data that can be stored in the table.

    DISTINCT is used in queries to remove duplicates from the result set, without affecting the underlying table data.

    0 讨论(0)
  • 2021-01-18 18:24

    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

    0 讨论(0)
  • 2021-01-18 18:33
    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.

    Please note that unique has many other meanings when used in other area's ie index creation etc.

    0 讨论(0)
  • 2021-01-18 18:37

    AFAIR both mean the same. To get unique vel distinct LAT & LONG from your table just do:

    SELECT DISTINCT LAT, LONG FROM table;

    0 讨论(0)
提交回复
热议问题