aspose 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
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply 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: 56157
    
  13

LIMIT is also available in PostgreSQL.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: What Is LIMIT? and How To Use LIMIT?
 
Similar Threads
Update Problem
server goes into sleep state while executing "Connection con=datasource.getConnection
Conditional 'where' condition
Clear bean values onLoad
ArrayList not clearing