SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    What does LIMIT do?

    Hi in MySQL, when I do LIMIT x, how does the database work?

    1) Does it pull everything relevant, then only takes the x starting from 0 or.

    2) Does it only pull the first x amount out and stops?

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    #2 whenever possible.

  3. #3
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    In the case of something like, ORDER BY column LIMIT 5, would it do #1. And if so is there a more efficient method of doing such?

    And if there's no column and it's just like SELECT * FROM tbl WHERE x=1 LIMIT 5, it would do #2?

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,262
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    it would use #2 if there is an ORDER BY and the order by column has an index

    i've always wondered why people would want to use LIMIT without ORDER BY -- it's not like you're going to get a random selection, you're not, you will probably get the earliest rows, but this isn't guaranteed
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •