|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
||||
|
||||
|
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? |
|
#2
|
|||
|
|||
|
correct.
|
|
#3
|
|||
|
|||
|
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. |
|
#4
|
||||
|
||||
|
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.
|
|
#5
|
|||
|
|||
|
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 |
|
#6
|
||||
|
||||
|
try using the SQL:
Code:
SELECT * FROM webnews ORDER BY articleid DESC LIMIT 1 |
![]() |
| Viewing: Dev Articles Community Forums > Databases > General SQL Development > SELECT MAX(field) FROM table |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|