Matt C
Matt C

Reputation: 147

Oracle SQL get one of each data

If I had a table with a column of Hello and I had multiple rows with the data 'World' and multiple with the data Dave (There are other columns too) and I wanted to select all the different types of data within the Hello column.

So basically I would be looking for a return with two results, one being World and the other being Dave.

Another option would be to count the how many different data pieces there are in the column(2 in this case) and searching with that as a rownum and sorting the results (Although I'd assume this was a very similar search.)

Thanks

Upvotes: 0

Views: 103

Answers (1)

Grisha Weintraub
Grisha Weintraub

Reputation: 7986

if you don't want duplicates in the result - add distinct :

select distinct hello from yourTable

and if you want to count different values :

select hello, count(*) from yourTable group by hello

Upvotes: 1

Related Questions