Reputation:
I have a table that contains multiple rows with duplicate ID
values:
ID | Course1 | Course2 |
---|---|---|
S1 | A1 | A2 |
S1 | A1 | B1 |
S2 | D1 | B1 |
S2 | C1 | B1 |
I need to select the first row for each unique ID
value, resulting in a table that includes only the first occurrence of each ID
.
The desired resulting table should look like this:
ID | Course1 | Course2 |
---|---|---|
S1 | A1 | A2 |
S2 | D1 | B1 |
Upvotes: 0
Views: 37
Reputation: 113
The easiest way (in my opinion) to select the first row for each ID
is to use a GROUP BY
statement. This will group the rows by their ID
and allow you to select the first row for each group. Here is an example query:
SELECT *
FROM YourTable
GROUP BY ID;
[
Upvotes: 1