Home > Net >  MySQL: Select only one type of value for shared id
MySQL: Select only one type of value for shared id

Time:05-03

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

CodePudding user response:

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;
  • Related