Reputation: 229
I've got several columns of data. The first column has all unique values that I only want to show up once. The second column may have multiple entries for the same data. This is causing the first column to show multiple entries, one for each entry in the second column.
Example:
A 123
A 432
A 2352
B 5342
C 34256
C 23423
I only want to see one row for A, one row for B, and one row for C. I don't care which value from the second column is displayed for each A/B/C row.
Upvotes: 0
Views: 72
Reputation: 247700
You can use an aggregate function to get the max
or min
value of the second column and then apply a group by
to col1
:
select col1, max(col2) as col2
from yourtable
group by col1
Upvotes: 1
Reputation: 263723
Use GROUP BY
clause.
The GROUP BY
clause can be used in an SQL SELECT statement to collect data across multiple records and group the results by one or more columns.
SELECT col1, MAX(col2) col2
FROM tableName
GROUP BY col1
Upvotes: 1