benpung:
THere is a story behind this:
Long, long time ago, Oracle RDBMS has this UNIQUE keyword even before ANSI SQL standard come into birth.
And no doubt, this UNIQUE is the oracle way of get distinct records.
but then ANSI SQL comes along, and say ok, every RDBMS gonna have to use DISTINCT, because this is the standard,
So Oracle add DISTINCT into its sql bank, but Did NOT decommission the UNIQUE.
there you go, so they are coexisting in ORacle.
you won't see anywhere else...
Main Topics
Browse All Topics





by: markgeerPosted on 2004-10-14 at 11:58:43ID: 12311173
I've never tried the "unique" keyword in a select statement, so I don't know. (I have used it often in a "create unique index..." statement, but I didn't even know it was valid in queries.)
Be careful with the "distinct" keyword. That can give you the results you expect when you select only one column. If you try it with multiple columns being selected, the results may surprise you - they may not be what you expect.
Also, the "distinct" keywork in a query always forces a sort operation, but depending on the data and the query, that may not be needed. If it is not needed, it is just a performance penalty to add it. Some people (especially those with SQL Server experience) tend to add the word "distinct" to most queries apparently out of habit. That is not a good habit in Oracle. Usually in Oracle, a group operator (like: count, sum, min, max, avg, etc.) on one column along with a "group by" clause for the other column(s) is more reliable than "distinct" when multiple columns are being returned by a query.