• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What Is LIMIT? and How To Use LIMIT?

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw somebody has MySQL statement this way:

StringBuffer sql = new StringBuffer(512);
sql.append("SELECT ThreadID, ForumID, MemberName, LastPostMemberName, ThreadTopic, ThreadBody");
sql.append(" FROM " + TABLE_NAME);
sql.append(" ORDER BY " + sort + " " + order);
sql.append(" LIMIT ?, ?");

What is LIMIT? What do those question marks stand for?
 
eammon bannon
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LIMIT I think is a MySQL-only SQL (I don't /think/ its in ANSI SQL-2, but I'd have to check). Its used to limit the amount of rows returned from a query expression e.g. LIMIT 10 would return a maximum of 10 results, even if the query expression could find more. You get similar thing in other DBs - SQL Server uses TOP in the same way for example.
The question marks are there to allow paramater binding. You would run this as a PreparedStatement and supply bind values to substitute in to the ?. That being said, I think LIMIT can only take one arguement, so I'd be surprised if the query works.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LIMIT is also available in PostgreSQL.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic