문제

my table Product:

-------------------------------
   id   |   name   |   alias   
-------------------------------
   1    |  Prod 1  |   ABC
-------------------------------
   2    |  Prod 2  |   DEF
-------------------------------
   3    |  Prod 3  |   GHK
-------------------------------
   4    |  Prod 4  |   ABC
-------------------------------
   5    |  Prod 5  |   ABC
-------------------------------
   6    |  Prod 6  |   DEF
-------------------------------

this's my query:

SELECT `name`
FORM `Product`
GROUP BY `alias`

this's result:

-------------------------------
   id   |   name   |   alias   
-------------------------------
   1    |  Prod 1  |   ABC
-------------------------------
   2    |  Prod 2  |   DEF
-------------------------------
   3    |  Prod 3  |   GHK
-------------------------------

but i want select max of id product for each record, ext: alias ABC -> 5, alias DEF -> 6, alias GHK -> 3, how i can do this? somebody can help me?

올바른 솔루션이 없습니다

다른 팁

The MAX method is known as an aggregate function, so in order for the query to determine what grouping to get the MAX of, you need to GROUP BY that column.

SELECT MAX(id), Name FROM Product GROUP BY alias
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top