function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rdclk23rdclk23 

SOQL Order by Limit

If you have a SOQL statement with ORDER BY and a LIMIT 100 clause, which executes first?  Does it order all records and then take the first 100 records or does it do the LIMIT first and then ORDER BY? 

VIMAL SRIVASTAVA.ax1855VIMAL SRIVASTAVA.ax1855

hello rdclk23

 

If you have a SOQL query like that thenit will order all records first, after that will apply the limits.

 

 

Hope this help!!!

 

Regards

VIMAL SRIVASTAVA

ericmonteericmonte

I agree to Vimal. It will query based on the Order then limit it.

 

http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select.htm

Akshay_DhimanAkshay_Dhiman
Hi rdclk23.

Try for this process.
List<Account> accList=new List<Account>();
accList==[SELECT id,
                    Name
     FROM Account
     ORDER BY Name ASC
     LIMIT 1000
];

Thanks
Akshay