|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
How do I write below sql statement in MySQL:
"SELECT TOP 5 * FROM some_table"? This sql statement work in SQL Server. |
|
#2
|
|||
|
|||
|
top 5 what?
select * from some_table order by some_field [asc|desc] limit 5 |
|
#3
|
|||
|
|||
|
Hi, Thanks for the help. By the way, I hardly find all these SQL statement supported by MySQL. Where can I find all these information? Is it only in MySQL manual?
Thanks. vic |
|
#4
|
|||
|
|||
|
As follows:
SELECT * FROM YourTableName LIMIT 5; The LIMIT # function works with the statement just like it does for the UPDATE statement. See: http://www.mysql.com/documentation/...nce.html#SELECT 7.14 SELECT syntax SELECT [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT] [HIGH_PRIORITY] [DISTINCT | DISTINCTROW | ALL] select_expression,... [INTO {OUTFILE | DUMPFILE} 'file_name' export_options] [FROM table_references [WHERE where_definition] [GROUP BY {unsigned_integer | col_name | formula}] [HAVING where_definition] [ORDER BY {unsigned_integer | col_name | formula} [ASC | DESC] ,...] [LIMIT [offset,] rows] [PROCEDURE procedure_name] ] ------------------ |
|
#5
|
|||
|
|||
|
Correcttion: you have to give a search criteria so that you get an ordering:
SELECT * FROM YourTableName ORDER BY yourColumnName ASC LIMIT 5; The LIMIT # function works with the statement just like it does for the UPDATE statement. See: http://www.mysql.com/documentation/...nce.html#SELECT 7.14 SELECT syntax SELECT [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT] [HIGH_PRIORITY] [DISTINCT | DISTINCTROW | ALL] select_expression,... [INTO {OUTFILE | DUMPFILE} 'file_name' export_options] [FROM table_references [WHERE where_definition] [GROUP BY {unsigned_integer | col_name | formula}] [HAVING where_definition] [ORDER BY {unsigned_integer | col_name | formula} [ASC | DESC] ,...] [LIMIT [offset,] rows] [PROCEDURE procedure_name] ] mailto:jcbell@magnolia.net ------------------ |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > select top row |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|