Thread: select top row

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    15
    Rep Power
    0
    How do I write below sql statement in MySQL:
    "SELECT TOP 5 * FROM some_table"?

    This sql statement work in SQL Server.
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    top 5 what?

    select * from some_table order by some_field [asc|desc] limit 5
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    15
    Rep Power
    0
    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
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    14
    Rep Power
    0
    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/m...ce.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] ]

    ------------------
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    14
    Rep Power
    0
    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/m...ce.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

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

Similar Threads

  1. div style="overflow: scroll;"
    By slydero in forum HTML Programming
    Replies: 8
    Last Post: October 26th, 2004, 09:54 AM
  2. row not inserting at end of table
    By sweetpotatoe in forum PHP Development
    Replies: 9
    Last Post: December 15th, 2003, 01:07 PM
  3. select top 3
    By codejockey in forum MS SQL Development
    Replies: 4
    Last Post: October 10th, 2003, 07:39 AM
  4. Creating An Excel Spreadsheet From Web Form Data
    By MGarde in forum ASP Programming
    Replies: 5
    Last Post: May 19th, 2003, 09:22 PM
  5. select count(DISTINCT column) all on one row
    By zakj in forum MySQL Help
    Replies: 2
    Last Post: April 16th, 2003, 01:39 PM

IMN logo majestic logo threadwatch logo seochat tools logo