'How to select only one type of value for shared id?

I wasn't sure how to word this but this is what I am looking for:

enter image description here

Currently my table looks like this:

enter image description here



Solution 1:[1]

On MySQL 8+, we can use RANK():

WITH cte AS (
    SELECT *, RANK() OVER (PARTITION BY common_id ORDER BY id) rnk
    FROM yourTable
)

SELECT id, string, common_id
FROM cte
WHERE rnk = 1;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tim Biegeleisen