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

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 25th, 2005, 02:15 PM
Morch Morch is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 2 Morch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 23 m 20 sec
Reputation Power: 0
Question Having problem with MAX function

I am having a little problem here with MAX function and would be very nice if anyone could guide me through this.


I have the table called sale1. I have several columns but I dont want to confuse you with all of them. Lets just say I have the following two columns with the two records::

sale_id number
SL0001 1
SL0002 2

Now to display the the maximum number we do the following:

select max(number) from sale1
Output: 2

How could I display the sale_id next to it?
Expected Output: SL0002 2


I tried lots of ways before posting this message. I did subquery as well.

select sale_id, number
from sale1
where number in (select max(number) from sale1);

The server gave me error. I dont know what the error i.......If anyone could give me some instructions it will be very nice.

Reply With Quote
  #2  
Old March 26th, 2005, 05:36 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
If all you want is the highest number, just do this:

Code:
 SELECT
  *
 FROM
  yourtable
 ORDER BY 
  number
   DESC
 LIMIT 1
 

Reply With Quote
  #3  
Old March 27th, 2005, 06:27 AM
Morch Morch is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 2 Morch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 23 m 20 sec
Reputation Power: 0
Thank you very much. That is all i wanted and it worked perfectly.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Having problem with MAX function


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 5 hosted by Hostway