O'Reilly logo

OCA Oracle Database 11g: SQL Fundamentals I: A Real-World Certification Guide by Steve Ries

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using DISTINCT to display unique values

Consider the address table, which lists all of our employees' addresses. Let us suppose that we want a report on which states our employees are from, to satisfy federal tax guidelines. We could do this using the following query:

Using DISTINCT to display unique values

The results give us what we asked for, but they are littered with duplicate values. If we want a concise list of states where our employees live, it would be preferable to discard duplicate values and display only a unique list of states. We can do this using the distinct keyword, as shown in the following example:

While the original query returned 16 rows, the query using DISTINCT

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required