June 26th, 2000, 03: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, 05:18 PM
Just select the field, sort it and take the first row at the top.
ORDER BY field DESC
June 29th, 2000, 07: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, 02:15 AM
*Is* there a MAX function?
June 30th, 2000, 06: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.