File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes What Is LIMIT? and How To Use LIMIT? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "What Is LIMIT? and How To Use LIMIT?" Watch "What Is LIMIT? and How To Use LIMIT?" New topic
Author

What Is LIMIT? and How To Use LIMIT?

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
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

Joined: Mar 16, 2004
Posts: 140
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

Joined: Jan 10, 2002
Posts: 61010
    
  65

LIMIT is also available in PostgreSQL.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What Is LIMIT? and How To Use LIMIT?