Skip to main content
Inspiring
September 2, 2010
Answered

3 most recent entries

  • September 2, 2010
  • 1 reply
  • 608 views

Hi,

I''ve been flipping through my Coldfusion book and can't seem to find out what kind of code I need to use to display the three most recent blogs in my database... the three highest 'blog_id'; numbers.

    This topic has been closed for replies.
    Correct answer ilssac

    wycks wrote:

    I''ve been flipping through my Coldfusion book and can't seem to find out what kind of code

    That may be because this is probably not a ColdFusion problem.  I presume your blog is stored in a database?  If so, then you probably want a database SQL solution.  The difficulty here, is that each major database management system has a different solution to this problem.

    Examples for some of the biggest:

    Postgresql:
    SELECT firstname, lastname, email
    FROM contacts
    LIMIT 3

    MS SQL Server:
    SELECT TOP 3 firstname, lastname, email
    FROM contacts

    ORACLE:
    SELECT firstname, lastname, email
    FROM contacts
    WHERE ROWNUM <= 3

    mySQL:
    SELECT firstname, lastname, email
    FROM contacts
    LIMIT 3

    http://blog.daemon.com.au/archives/000301.html

    But if you really wanted to, you could probably get the results you want with the ColdFusion 'maxrows' parameter of the <cfquery...> tag.

    1 reply

    ilssac
    ilssacCorrect answer
    Inspiring
    September 2, 2010

    wycks wrote:

    I''ve been flipping through my Coldfusion book and can't seem to find out what kind of code

    That may be because this is probably not a ColdFusion problem.  I presume your blog is stored in a database?  If so, then you probably want a database SQL solution.  The difficulty here, is that each major database management system has a different solution to this problem.

    Examples for some of the biggest:

    Postgresql:
    SELECT firstname, lastname, email
    FROM contacts
    LIMIT 3

    MS SQL Server:
    SELECT TOP 3 firstname, lastname, email
    FROM contacts

    ORACLE:
    SELECT firstname, lastname, email
    FROM contacts
    WHERE ROWNUM <= 3

    mySQL:
    SELECT firstname, lastname, email
    FROM contacts
    LIMIT 3

    http://blog.daemon.com.au/archives/000301.html

    But if you really wanted to, you could probably get the results you want with the ColdFusion 'maxrows' parameter of the <cfquery...> tag.

    Inspiring
    September 2, 2010

    Regarding:

    But if you really wanted to, you could probably get the results you want  with the ColdFusion 'maxrows' parameter of the <cfquery...> tag.

    Bad idea.  It works but it's inefficient.

    ilssac
    Inspiring
    September 2, 2010

    Dan Bracuk wrote:

    Bad idea.  It works but it's inefficient.

    Which is why it is listed last and qualifed with "really wanted to".