General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL 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 July 8th, 2003, 10:59 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
SELECT MAX(field) FROM table

to find the highest number in a table, i would use:
SELECT MAX(field) FROM table

how would i go about finding the ten highest numbers?

Reply With Quote
  #2  
Old July 8th, 2003, 11:07 PM
fatal fatal is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 9 fatal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
correct.

Reply With Quote
  #3  
Old July 8th, 2003, 11:27 PM
iahmed iahmed is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: USA
Posts: 171 iahmed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 58 sec
Reputation Power: 6
Following may work, please try it:


select distinct FIELD1 from TABLE1 order by FIELD1 desc limit 10



Variation of "LIMIT" across diffrerent SQL engine
===============================

MySQL uses LIMIT
ORACLE uses ROWNUM
Microsoft SQL uses TOP

MSSQL Example:
===============

To return the top 10 highest paid employees:

SELECT TOP 10 empid, empname, salary
FROM employees
ORDER BY salary DESC

ORACLE Example:
==============

select rownum, col1 from table1 where rownum between 1 and 10



Last edited by iahmed : July 9th, 2003 at 01:05 AM.

Reply With Quote
  #4  
Old July 8th, 2003, 11:50 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Unfortunately, there is no standard for LIMIT/TOP keywords. It varies from each RDBMS. The best way to find out which is correct for your platform is to simply read the documentation.
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #5  
Old January 6th, 2004, 05:36 PM
tsclan tsclan is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 6 tsclan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
needing to find highest id num

I am making a news script where it can only show 1 news item at a time and the latest one needs to always to be seen
I am using id with auto increment and therefore the newsest post will be the highest id number i wonder if u could help me by showing me how to automatically show the latest news item
this is what i have so far

<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM webnews WHERE id='$id'";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();



?>
<?
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$by=mysql_result($result,$i,"by");
$snews=mysql_result($result,$i,"snews");
$fnews=mysql_result($result,$i,"fnews");
$date=mysql_result($result,$i,"date");

?>
<p><? echo "$id"; ?></p>
<p><? echo "$by"; ?></p>
<p><? echo "$snews"; ?></p>
<p><? echo "$fnews"; ?></p>
<p><? echo "$date"; ?></p>
<?
++$i;
}


?>
--------------------------------------------
I may be going to wrong way about it, so any help would be greatly appreciated


thank you

Reply With Quote
  #6  
Old January 6th, 2004, 05:55 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
try using the SQL:
Code:
SELECT * FROM webnews ORDER BY articleid DESC LIMIT 1

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > SELECT MAX(field) FROM table


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