★ wanayoo — archive 1999 http://www.devshed.com/Talk/Forums/Forum4/HTML/000715.htmlNouvelle recherche | Portail wanayoo
DevShed Menu
* DevShed Home
* Developer News
* DevShed Brain Dump




UBBFriend: Email This Page to Someone!
  DevShed Discussion Forums
  MySQL
  select top row

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   select top row
vic
Junior Member
posted July 14, 2000 09:46 PM     Click Here to See the Profile for vic   Click Here to Email vic     Edit/Delete Message Reply w/Quote
How do I write below sql statement in MySQL:
"SELECT TOP 5 * FROM some_table"?

This sql statement work in SQL Server.

rod k
Member
posted July 15, 2000 04:49 AM     Click Here to See the Profile for rod k   Click Here to Email rod k     Edit/Delete Message Reply w/Quote
top 5 what?

select * from some_table order by some_field [asc|desc] limit 5

vic
Junior Member
posted July 15, 2000 09:20 AM     Click Here to See the Profile for vic   Click Here to Email vic     Edit/Delete Message Reply w/Quote
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

jcbell
Member
posted July 15, 2000 07:24 PM     Click Here to See the Profile for jcbell   Click Here to Email jcbell     Edit/Delete Message Reply w/Quote
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/mysql/bychapter/manual_Reference.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] ]

------------------

jcbell
Member
posted July 15, 2000 07:28 PM     Click Here to See the Profile for jcbell   Click Here to Email jcbell     Edit/Delete Message Reply w/Quote
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/mysql/bychapter/manual_Reference.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

------------------

All times are MST (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | DevShed.com

Copyright © 1997-2000 ngenuity. All rights reserved.

Powered by: Ultimate Bulletin Board, Version 5.41a
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 1999.