MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old June 26th, 2000, 03:12 PM
ryanh ryanh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 1999
Posts: 119 ryanh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 41 sec
Reputation Power: 9
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...

Reply With Quote
  #2  
Old June 26th, 2000, 05:18 PM
Adrian2 Adrian2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: London, England
Posts: 251 Adrian2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Just select the field, sort it and take the first row at the top.

SELECT field
FROM table
ORDER BY field DESC
LIMIT 1

Reply With Quote
  #3  
Old June 29th, 2000, 07:11 PM
Jinn Jinn is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 13 Jinn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I have a question: which way is better to find the max: using limit and order by, or using MAX?

Reply With Quote
  #4  
Old June 30th, 2000, 02:15 AM
ryanh ryanh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 1999
Posts: 119 ryanh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 41 sec
Reputation Power: 9
*Is* there a MAX function?

Reply With Quote
  #5  
Old June 30th, 2000, 06:39 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > MAX function in MySQL??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway