{"id":1483,"date":"2026-09-04T17:00:00","date_gmt":"2026-09-04T11:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/"},"modified":"2026-09-04T17:00:00","modified_gmt":"2026-09-04T11:30:00","slug":"soql-where-clause-order-by-limit","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/","title":{"rendered":"SOQL WHERE Clause, ORDER BY, LIMIT and OFFSET in Apex"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The SOQL WHERE Clause decides which records your query returns. ORDER BY decides their order, LIMIT decides how many come back, and OFFSET skips rows for paging. So together, these four keywords turn a broad query into a precise one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, you will learn every common filter operator, how to combine conditions, and how to sort and page results safely. It continues from <a href=\"https:\/\/swapnilzambare.com\/blog\/soql-basics-first-query-apex\/\">SOQL Basics<\/a> and uses the <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-operators-expressions\/\">Apex operators<\/a> and <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-conditional-statements-if-switch\/\">conditional statements<\/a> you already know. As before, we will keep using the Course__c object from Bright Path Tutors.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is the SOQL WHERE Clause?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The SOQL WHERE Clause is the part of a query that filters records. It contains one or more conditions, such as <code>Fee__c &gt; 5000<\/code>. As a result, only records that match every rule come back. However, without a WHERE clause, the query returns every record the user can see.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a school notice: &#8220;Students of Class 8, Section B, with attendance below 75%, must meet the principal.&#8221; Each part narrows the group. In the same way, a SOQL WHERE Clause narrows records.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why the SOQL WHERE Clause Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Good filters keep queries fast, and they also keep code within limits. Here is why the SOQL WHERE Clause matters at Bright Path Tutors.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, the reminder job needs only courses that start next week.<\/li>\n\n<li>Also, the website shows online beginner courses under 5,000 rupees.<\/li>\n\n<li>Next, the course list page shows 20 courses at a time, newest first.<\/li>\n\n<li>Also, a report class must skip cancelled enrolments.<\/li>\n\n<li>Finally, unfiltered queries can return 50,000 rows and break the transaction.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">So clear filters give correct results and protect your limits.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the SOQL WHERE Clause Works with ORDER BY, LIMIT and OFFSET<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Salesforce runs these clauses in a set order, so the SOQL WHERE Clause always runs before sorting. First, FROM picks the object. Next, the SOQL WHERE Clause filters the records. Then ORDER BY sorts the remaining rows. After that, OFFSET skips a number of rows. Finally, LIMIT caps how many rows come back.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-diagram-1-1024x640.png\" alt=\"SOQL WHERE Clause diagram showing FROM, WHERE, ORDER BY, OFFSET and LIMIT order\" class=\"wp-image-1481\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-diagram-1-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-diagram-1-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">The order in which SOQL clauses run.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Comparison Operators<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The basic operators are <code>=<\/code>, <code>!=<\/code>, <code>&lt;<\/code>, <code>&lt;=<\/code>, <code>&gt;<\/code> and <code>&gt;=<\/code>. Text comparisons are not case sensitive, so <code>Name = 'apex basics'<\/code> matches &#8220;Apex Basics&#8221;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">LIKE<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">LIKE matches text patterns, for example course names. The <code>%<\/code> sign matches any number of characters, and <code>_<\/code> matches exactly one. For example, <code>Name LIKE 'Apex%'<\/code> finds names that start with Apex.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">IN and NOT IN<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">IN checks a value against a list, such as <code>Level__c IN ('Beginner', 'Intermediate')<\/code>. In Apex, you can also pass a list or set with a bind variable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">AND, OR and NOT<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">AND needs both conditions to be true, and OR needs at least one. Use brackets when you mix them, so the meaning is clear.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Null Checks<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>Fee__c = null<\/code> to find blank values and <code>Fee__c != null<\/code> to find filled ones. However, SOQL does not use IS NULL.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SOQL WHERE Clause Operators at a Glance<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below lists the operators you will use most.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Operator<\/th><th>Example<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td>=<\/td><td>Level__c = &#8216;Beginner&#8217;<\/td><td>Equal to<\/td><\/tr><tr><td>!=<\/td><td>Level__c != &#8216;Advanced&#8217;<\/td><td>Not equal to<\/td><\/tr><tr><td>&gt; and &lt;<\/td><td>Fee__c &gt; 5000<\/td><td>Greater or less than<\/td><\/tr><tr><td>LIKE<\/td><td>Name LIKE &#8216;Apex%&#8217;<\/td><td>Text pattern<\/td><\/tr><tr><td>IN<\/td><td>Level__c IN (&#8216;Beginner&#8217;, &#8216;Intermediate&#8217;)<\/td><td>Matches any value in a list<\/td><\/tr><tr><td>INCLUDES<\/td><td>Topics__c INCLUDES (&#8216;Apex&#8217;)<\/td><td>Multi-select picklist contains a value<\/td><\/tr><tr><td>= null<\/td><td>Start_Date__c = null<\/td><td>Field is blank<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">OFFSET Paging vs Keyset Paging<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Paging means showing results page by page, for example 20 rows at a time. The table below compares two common approaches.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>OFFSET paging<\/th><th>Keyset paging<\/th><\/tr><\/thead><tbody><tr><td>How it works<\/td><td>Skip N rows with OFFSET<\/td><td>Filter after the last seen value<\/td><\/tr><tr><td>Example<\/td><td>LIMIT 20 OFFSET 40<\/td><td>WHERE Name &gt; :lastName LIMIT 20<\/td><\/tr><tr><td>Maximum depth<\/td><td>OFFSET up to 2,000<\/td><td>No fixed depth limit<\/td><\/tr><tr><td>Speed on deep pages<\/td><td>Slower<\/td><td>Stays fast<\/td><\/tr><tr><td>Easy to jump to page 5<\/td><td>Yes<\/td><td>No, only next and previous<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When to use which depends on the data size. So use OFFSET for small lists. Use keyset paging when users may scroll through thousands of records.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-diagram-2-1024x640.png\" alt=\"SOQL WHERE Clause diagram comparing OFFSET paging and keyset paging\" class=\"wp-image-1482\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-diagram-2-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-diagram-2-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">OFFSET paging vs keyset paging.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">A Real SOQL WHERE Clause Example in Apex<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s build filters for the Bright Path Tutors course catalogue. The website needs affordable online courses for beginners, sorted by start date, 10 per page.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Combine Filters<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;Course__c&gt; catalogue = [\n    SELECT Id, Name, Fee__c, Level__c, Start_Date__c\n    FROM Course__c\n    WHERE Is_Online__c = true\n    AND Level__c IN ('Beginner', 'Intermediate')\n    AND (Fee__c &lt; 5000 OR Name LIKE '%Basics%')\n    ORDER BY Start_Date__c ASC NULLS LAST\n    LIMIT 10\n];\nSystem.debug('Courses on page 1: ' + catalogue.size());<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, the query keeps online courses at two levels. Then the bracketed OR keeps cheap courses or any &#8220;Basics&#8221; course. ORDER BY sorts by start date, and NULLS LAST puts undated courses at the end. LIMIT 10 returns only the first page.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Add Paging with OFFSET<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Integer pageSize = 10;\nInteger pageNumber = 3;\nInteger offsetRows = (pageNumber - 1) * pageSize;\n\nList&lt;Course__c&gt; page3 = [\n    SELECT Id, Name, Start_Date__c\n    FROM Course__c\n    WHERE Is_Online__c = true\n    ORDER BY Start_Date__c ASC, Name ASC\n    LIMIT :pageSize\n    OFFSET :offsetRows\n];\nSystem.debug('Page 3 first course: ' + (page3.isEmpty() ? 'none' : page3[0].Name));<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The colon starts a bind variable, which inserts an Apex value into the query. Here offsetRows is 20, so OFFSET skips the first 20 rows and we get page 3. Sorting by start date and then name keeps the order stable between pages.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Read the Output<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here is an example of the debug log for these two blocks.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>USER_DEBUG [10]|DEBUG|Courses on page 1: 10\nUSER_DEBUG [13]|DEBUG|Page 3 first course: Data Loader Basics<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Dates and Booleans in the SOQL WHERE Clause<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">However, some values never use quotes. Booleans are <code>true<\/code> or <code>false<\/code>. Dates use the format <code>2026-09-15<\/code>, and date times use <code>2026-09-15T09:00:00Z<\/code>. In contrast, text values always need single quotes. In the next topics, you will also use date literals such as <code>NEXT_N_DAYS:7<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with the SOQL WHERE Clause<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Putting quotes around numbers, booleans or dates.<\/li>\n\n<li>Mixing AND and OR without brackets, which changes the meaning.<\/li>\n\n<li>Using OFFSET without ORDER BY, so pages overlap or skip records.<\/li>\n\n<li>Using OFFSET beyond 2,000, which throws an error.<\/li>\n\n<li>Starting LIKE patterns with %, which can make large queries slow.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for the SOQL WHERE Clause<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Filter on indexed fields, such as Id, Name, lookups and external IDs.<\/li>\n\n<li>Always pair OFFSET with ORDER BY.<\/li>\n\n<li>Use bind variables instead of joining strings.<\/li>\n\n<li>Add LIMIT whenever you need only a few rows.<\/li>\n\n<li>Use keyset paging for large or deep result sets.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Write a query that returns the 5 most expensive advanced courses that are not online. Hint: combine Level__c, Is_Online__c, ORDER BY Fee__c DESC and LIMIT 5.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked Interview Questions on the SOQL WHERE Clause<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Questions on the SOQL WHERE Clause and paging come up in nearly every developer interview. Here are the 20 most asked questions, with short answers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Questions on the SOQL WHERE Clause<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1: What does the WHERE clause do in SOQL?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It filters records, so the query returns only rows that match the conditions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2: Are text comparisons in SOQL case sensitive?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. So text comparisons with = and LIKE match any case.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3: What wildcards does LIKE support?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The % sign matches any number of characters, and _ matches exactly one character.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4: How do you check for blank values?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use = null for blank and != null for filled values, because SOQL does not support IS NULL.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5: How do you filter a multi-select picklist?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use INCLUDES or EXCLUDES, such as Topics__c INCLUDES (&#8216;Apex&#8217;).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6: Do booleans and dates need quotes?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. For example, booleans are true or false, and dates use YYYY-MM-DD without quotes. Only text needs single quotes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7: What does ORDER BY NULLS LAST do?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It puts rows with blank values in the sort field at the end of the results.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Code and Scenario Questions on the SOQL WHERE Clause<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8: How do you filter by a list of values from Apex?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use IN with a bind variable, such as WHERE Id IN :courseIds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9: What is the maximum OFFSET value?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The limit is 2,000, so a larger OFFSET throws an error.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10: Why should OFFSET always be used with ORDER BY?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Without a fixed order, the database may return rows in a different order each time, so pages can overlap or skip records.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11: How do you get the newest five courses?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, use ORDER BY CreatedDate DESC LIMIT 5.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12: What happens if you mix AND and OR without brackets?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">AND is evaluated before OR, which can give unexpected results. So brackets make the intent clear.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13: How do you sort by more than one field?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">List the fields after ORDER BY, separated by commas, such as ORDER BY Level__c ASC, Fee__c DESC.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14: How would you show page 4 of a 25-row list?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, use LIMIT 25 OFFSET 75 with a stable ORDER BY.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced Questions on the SOQL WHERE Clause<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15: What is keyset paging?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It filters after the last value seen on the previous page, such as WHERE Name &gt; :lastName ORDER BY Name. As a result, it stays fast on deep pages.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16: Which fields are indexed by default?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, common ones include Id, Name, OwnerId, CreatedDate, SystemModstamp, lookup and master-detail fields, and external ID or unique fields.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17: Why can a LIKE filter starting with % be slow?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A leading wildcard cannot use an index, so Salesforce may scan many more rows.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18: What is a selective query?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is a query whose filters use indexes and return a small share of the records. Because of this, selective queries stay fast on large objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19: Can you use a formula field in a WHERE clause?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Often yes, but formula fields are usually not indexed, so filtering on them can be slow on large objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20: How do you avoid hitting the 50,000 row limit?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, use tight filters and LIMIT. Then process large data in Batch Apex, and avoid queries without a WHERE clause on big objects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.soql_sosl.meta\/soql_sosl\/sforce_api_calls_soql_select_conditionexpression.htm\" target=\"_blank\" rel=\"noopener noreferrer\">WHERE Clause (Salesforce Developers)<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.soql_sosl.meta\/soql_sosl\/sforce_api_calls_soql.htm\" target=\"_blank\" rel=\"noopener noreferrer\">SOQL and SOSL Reference (Salesforce Developers)<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The SOQL WHERE Clause filters records with operators, LIKE, IN and null checks.<\/li>\n\n<li>ORDER BY sorts results, and NULLS FIRST or LAST controls blank values.<\/li>\n\n<li>Also, LIMIT caps the number of rows returned.<\/li>\n\n<li>OFFSET pages results up to 2,000 rows, always with ORDER BY.<\/li>\n\n<li>Use keyset paging and indexed filters for large data.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">So far, we have queried one object at a time. Next, learn to read parent and child records together in our guide to <a href=\"https:\/\/swapnilzambare.com\/blog\/soql-relationship-queries-parent-child\/\">SOQL relationship queries<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The SOQL WHERE Clause decides which records your query returns. ORDER BY decides their order, LIMIT decides how many come back, and OFFSET skips&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1480,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[8,96],"tags":[98,26,91,7,97,105],"swapz_series":[],"class_list":["post-1483","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce","category-salesforce-developer","tag-apex","tag-intermediate","tag-interview-questions","tag-salesforce","tag-salesforce-developer","tag-soql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SOQL WHERE Clause, ORDER BY, LIMIT and OFFSET<\/title>\n<meta name=\"description\" content=\"SOQL WHERE Clause explained simply: operators, LIKE, IN, AND and OR, null checks, ORDER BY, LIMIT, OFFSET paging and 20 interview questions.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SOQL WHERE Clause, ORDER BY, LIMIT and OFFSET\" \/>\n<meta property=\"og:description\" content=\"SOQL WHERE Clause explained simply: operators, LIKE, IN, AND and OR, null checks, ORDER BY, LIMIT, OFFSET paging and 20 interview questions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-04T11:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/soql-where-clause-order-by-limit\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/soql-where-clause-order-by-limit\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\"},\"headline\":\"SOQL WHERE Clause, ORDER BY, LIMIT and OFFSET in Apex\",\"datePublished\":\"2026-09-04T11:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/soql-where-clause-order-by-limit\\\/\"},\"wordCount\":1615,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/soql-where-clause-order-by-limit\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/soql-where-clause-order-by-limit-featured.png\",\"keywords\":[\"Apex\",\"Intermediate\",\"Interview Questions\",\"Salesforce\",\"Salesforce Developer\",\"SOQL\"],\"articleSection\":[\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/soql-where-clause-order-by-limit\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/soql-where-clause-order-by-limit\\\/\",\"name\":\"SOQL WHERE Clause, ORDER BY, LIMIT and OFFSET\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/soql-where-clause-order-by-limit\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/soql-where-clause-order-by-limit\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/soql-where-clause-order-by-limit-featured.png\",\"datePublished\":\"2026-09-04T11:30:00+00:00\",\"description\":\"SOQL WHERE Clause explained simply: operators, LIKE, IN, AND and OR, null checks, ORDER BY, LIMIT, OFFSET paging and 20 interview questions.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/soql-where-clause-order-by-limit\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/soql-where-clause-order-by-limit\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/soql-where-clause-order-by-limit\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/soql-where-clause-order-by-limit-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/soql-where-clause-order-by-limit-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"SOQL WHERE Clause featured image: title card with an Apex code example\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/soql-where-clause-order-by-limit\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SOQL WHERE Clause, ORDER BY, LIMIT and OFFSET in Apex\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SOQL WHERE Clause, ORDER BY, LIMIT and OFFSET","description":"SOQL WHERE Clause explained simply: operators, LIKE, IN, AND and OR, null checks, ORDER BY, LIMIT, OFFSET paging and 20 interview questions.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/","og_locale":"en_US","og_type":"article","og_title":"SOQL WHERE Clause, ORDER BY, LIMIT and OFFSET","og_description":"SOQL WHERE Clause explained simply: operators, LIKE, IN, AND and OR, null checks, ORDER BY, LIMIT, OFFSET paging and 20 interview questions.","og_url":"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-09-04T11:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a"},"headline":"SOQL WHERE Clause, ORDER BY, LIMIT and OFFSET in Apex","datePublished":"2026-09-04T11:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/"},"wordCount":1615,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-featured.png","keywords":["Apex","Intermediate","Interview Questions","Salesforce","Salesforce Developer","SOQL"],"articleSection":["Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/","url":"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/","name":"SOQL WHERE Clause, ORDER BY, LIMIT and OFFSET","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-featured.png","datePublished":"2026-09-04T11:30:00+00:00","description":"SOQL WHERE Clause explained simply: operators, LIKE, IN, AND and OR, null checks, ORDER BY, LIMIT, OFFSET paging and 20 interview questions.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/soql-where-clause-order-by-limit-featured.png","width":2400,"height":1260,"caption":"SOQL WHERE Clause featured image: title card with an Apex code example"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/soql-where-clause-order-by-limit\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"SOQL WHERE Clause, ORDER BY, LIMIT and OFFSET in Apex"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=1483"}],"version-history":[{"count":0,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1483\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/1480"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=1483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=1483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=1483"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=1483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}