Results 1 to 10 of 10
  1. #1
    Join Date
    Jul 2004
    Posts
    14

    Unanswered: How to select 5 results only ?

    Hi, thakns for reading my post

    What is the sql, command to select only 5 results from my table ?

    I mean, when I have a table with 100 replies to one topic, and I want to select only 5 of them.

    Thanks a lot

  2. #2
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    Oracle:

    Select columns
    from table
    where rownum <= 5

    SQL Server 2000:

    Select top 5 columns
    from table
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  3. #3
    Join Date
    Jul 2004
    Posts
    14
    Thanks a lot, gonna try it at once.

  4. #4
    Join Date
    Jul 2004
    Posts
    13

    Sql

    or u have to use the LIMIT statement
    optional LIMIT OFF

  5. #5
    Join Date
    Jul 2004
    Posts
    14
    Hmm, this doesnt works on my sql server

    I tried : "select * from Table where rownum=<5";
    and also : "select top 5 colums from table";

  6. #6
    Join Date
    Jul 2004
    Posts
    14
    Quote Originally Posted by laals
    or u have to use the LIMIT statement
    optional LIMIT OFF

    How to use Limit statement please ?
    Thanks

  7. #7
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    This query will work in MS SQL Server 2000:
    Code:
    Select top 5 *
    from table
    Last edited by r123456; 07-26-04 at 09:38.
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  8. #8
    Join Date
    Jul 2004
    Posts
    14
    Still doesn't work :/

    Code:
    $sql="Select top 2 * from clen";
    $res=mysql_query($sql);
    while($line=mysql_fetch_assoc($res)) echo($line[0]);
    gives :
    Code:
     Supplied argument is not a valid MySQL result resource in /home/... /html/lib.php on line 258

  9. #9
    Join Date
    Jul 2004
    Posts
    3
    SELECT * FROM yourtable LIMIT 2

    Looks like you are using MySQL, not Microsoft SQL Server. the TOP statement works in Microsoft SQL Server but I don't think it is in MySQL as a valid statement.

  10. #10
    Join Date
    Jul 2004
    Posts
    14
    Yes that's it
    It works
    Thanks a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •