SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict mh8759's Avatar
    Join Date
    Jun 2000
    Location
    Slovenia, Europe
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    limiting number of records

    I made a search on these forums, but couldn't find the answer for this question.
    I want to select N records from table that have been added most recently. In PHP/MySQL that can be done like this

    SELECT * FROM Table ORDER BY ID DESC LIMIT 3

    But in ASP it produces error:
    Error Type:
    Microsoft JET Database Engine (0x80040E14)
    Syntax error in ORDER BY clause.
    /Spletni projekti/RSH nova stran/default.asp, line 124

    I don't know how to acomplish that. Somebody must have solved this already.

    Thanks for you help
    Mare

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LIMIT is not part of the SQL standard and is proprietary to MySQL

    There are ways you can do this in your ASP however... I just don't know them. You can also do it in ColdFusion by utilizing the MaxRows and StartRow attributes of the query tag.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  3. #3
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Set the RS.MaxRecords property to whatever number you want. then execute your query?
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  4. #4
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Set the RS.MaxRecords property to whatever number you want. Then execute your query. It usually works. You can also do "SELECT FIRST 5 FROM", or something like that..

    good luck! Any questions? I'm just a click away.
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  5. #5
    SitePoint Member
    Join Date
    Jun 2001
    Location
    madison, WI
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should also work, and would be my choice. Should work in latest sql server/access versions

    SELECT Top N * FROM Table ORDER BY ID DESC LIMIT 3

    -where N = number of records you want returned.

    -hope it help....
    http://www.searchnightlife.com
    info@searchnightlife.com

  6. #6
    SitePoint Member
    Join Date
    Jun 2001
    Location
    madison, WI
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whoops, for to take out the end of your sql statement

    SELECT Top N * FROM Table ORDER BY ID DESC

    -where N = number of records you want returned.

    -hope it help....
    http://www.searchnightlife.com
    info@searchnightlife.com


Bookmarks

Posting Permissions

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