We've been getting a number of this type of question lately: short, and simple on the surface. Short questions...
are wonderful, because they leave more room for the answer. Simple questions are even better, as long as they aren't too simple.
In this case, there are two ways to do it.
select distinct col1 , col2 from daTable
This method uses the standard SQL keyword DISTINCT. All distinct combinations of values in two columns are shown. (It could be two, or 10, or even just one column.) The "distinctness" applies to the entire row produced by the query. Every result row is completely distinct.
select col1 , col2 from daTable group by col1 , col2
This method uses the standard SQL keywords GROUP BY. All distinct combinations of values in two columns are shown. (It could be two, or 10, or even just one column.) The "distinctness" applies to the columns in the GROUP BY. Every result row will be completely distinct in those two columns.
If you wanted distinct rows by those two columns, but with additional columns as well, then the question was indeed not as simple as it first appeared. In that case, perhaps the answer DISTINCT is not a function (26 September 2005) may help.
Dig Deeper on Oracle and SQL
Related Q&A from Rudy Limeback
Read an example of an SQL case expression from our SQL expert Rudy Limeback. Continue Reading
Read SQL expert Rudy Limeback's advice for counting combinations in a table with SQL's GROUP BY clause Continue Reading
Read about the Mimer Validator, a tool used to verify your SQL code, in this tip from SQL expert Rudy Limeback. Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.