db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Harri Pesonen <fue...@nic.fi>
Subject Re: Top 1 - Limit 1
Date Sat, 16 Sep 2006 13:28:44 GMT
It would be great if Derby had TOP (as in SQL Server) and LIMIT (as in 
MySql), because DataSet does not allow setMaxRows. TOP and LIMIT should 
support variables:

@Select("SELECT TOP ?1 * FROM Users WHERE Pin IS NULL")
DataSet<Users> getWithoutPin(int top);

-- Harri

Tim Dudgeon wrote:
> 
> 
> Bernt M. Johnsen wrote:
>> Tim Dudgeon wrote:
>>>
>>> Yes, but is there an equivalent to the TOP or LIMIT keywords that other
>>> databases use?
>>
>> Not in SQL (neither in Derby nor the SQL standard).
>> The closest equivalent is Statement.setMaxRows(i).
>>
> 
> So that would not be applied at the query level?
> 
> Statement stmt = con.createStatement();
> stmt.setMaxRows(1);
> stmt.execute("SELECT * FROM a_very_large_table");
> 
> would run very inefficiently?
> And how about
> 
> SELECT * FROM a_very_large_table ORDER BY some_column ?
> 
> 
> using a SQL keyword like TOP or LIMIT presumably allows these to be 
> optimised in some way, but stmt.setMaxRows(1) does not?
> 
> Tim
> 
> 
> 


Mime
View raw message