Reputation: 71
Hi there wondering if anyone can help me, this might not be the best description but I will try my best. I have a table which has a column that has many repeating values.
COL1|COL2|COL3
1 data data
1 data data
1 data data
2 data data
2 data data
I want a query that returns only 1 of the repeated values of col1. So the query does this.
COL1
1
2
Is this even possible and how would I be able to do it?
Upvotes: 0
Views: 1992
Reputation: 1270463
If you only want the first column, then:
select distinct col1
from t;
This may not do what you expect if you have multiple columns.
If you want complete rows, but only one per value, then use row_number()
:
select t.*
from (select t.*, row_number() over (partition by col1 order by col1) as seqnum
from t
) t
where seqnum = 1;
Upvotes: 0
Reputation: 515
Use the DISTINCT
keywords after SELECT
statement
As in
SELECT DISTINCT * FROM ...
Upvotes: 3