UNIQUE vs DISTINCT, what’s the difference?

20 pts.
Tags:
SQL
What is the difference between UNIQUE vs DISTINCT when used in a select statement? The result sets would seem to be the same, but is there a performance gain by using one over the other? If it matters, we're on Oracle 9i

Answer Wiki

Thanks. We'll let you know when a new response is added.

Quoting from online Oracle 9i SQL Reference:

“Specify DISTINCT or UNIQUE if you want Oracle to return only one copy of each set of duplicate rows selected (these two keywords are synonymous). Duplicate rows are those with matching values for each expression in the select list.”

So, there should be no difference in the two (performance or otherwise) as they are treated the same by Oracle.

On another note, don’t try to use UNIQUE in SELECT statements for other databases (MySQL, PostgreSQL, etc). You get up with an error because ANSI standards use DISTINCT with SELECT statements. Using UNIQUE with SELECT statements is just a product specific remnant of older Oracle DBs created before the ANSI standard was born.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • smford
    Excellent! Thanks for the quick response.
    20 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following