How to return rows that have the same column values in MySql

前端 未结 3 1637
隐瞒了意图╮
隐瞒了意图╮ 2020-11-21 22:47

Lets consider the following table-

ID Score
1  95

2  100

3  88

4  100

5  73

I am a total SQL noob but how do I return the Scores featur

3条回答
  •  孤城傲影
    2020-11-21 22:59

    SELECT score
    FROM t
    WHERE id in (2, 4)
    HAVING COUNT(*) = 2 /* replace this with the number of IDs */
    

    This selects the rows with ID 2 and 4. The HAVING clause then ensures that we found both rows; if either is missing, the count will be less than 2.

    This assumes that id is a unique column.

提交回复
热议问题