June 26th, 2000, 04:12 PM
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...
June 26th, 2000, 06:18 PM
Just select the field, sort it and take the first row at the top.
ORDER BY field DESC
June 29th, 2000, 08:11 PM
I have a question: which way is better to find the max: using limit and order by, or using MAX?
June 30th, 2000, 03:15 AM
*Is* there a MAX function?
June 30th, 2000, 07:39 AM
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.