How to select DISTINCT rows without having the ORDER BY field selected

前端 未结 6 949
我寻月下人不归
我寻月下人不归 2021-01-06 15:49

So I have two tables students (PK sID) and mentors (PK pID). This query

SELECT s.pID
FROM students s JOIN mentors m ON s.pID = m.pID
WHERE m.tags LIKE \'%a%\         


        
6条回答
  •  伪装坚强ぢ
    2021-01-06 16:40

    SELECT s.pID
    FROM students s JOIN mentors m ON s.pID = m.pID   
    WHERE m.tags LIKE '%a%'
    GROUP BY s.pID
    ORDER BY MAX(s.sID) DESC
    

提交回复
热议问题