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
Question
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?
No correct solution
OTHER TIPS
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