|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
I need to find the largest value of a field within a given table. For example, I have an AUTO_INCREMENT column, and I need to find the largest value... How do you do that? sorry if this is an ignorant question...
![]() |
|
#2
|
|||
|
|||
|
Just select the field, sort it and take the first row at the top.
SELECT field FROM table ORDER BY field DESC LIMIT 1 |
|
#3
|
|||
|
|||
|
I have a question: which way is better to find the max: using limit and order by, or using MAX?
|
|
#4
|
|||
|
|||
|
*Is* there a MAX function?
|
|
#5
|
|||
|
|||
|
Use limit and order_by. max() should be used if you want to return several max values. For example, let's say you have a table with products that has the product_id, a category_id and price. You need to find the most expensive product in each category. You could do this:
select product_id,category_id,max(price) as m_price from products group by category_id order by category_id; This would return the most expensive product for each category. |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > MAX function in MySQL?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|