---
title: "View source for Querying Filtering - DreamFactory Wiki"
source: "http://wiki.dreamfactory.com/index.php?action=edit&title=Querying_Filtering"
canonical_url: "http://wiki.dreamfactory.com/index.php?action=edit&title=Querying_Filtering"
converted_at: "2026-11-25T12:12:08.475Z"
format: "markdown"
converted_by: "html-to-md-ai"
---
[]()
	
	
	
	# View source for Querying Filtering

	
		
		← [Querying Filtering](/Querying_Filtering)
		
		
		
		[Jump to navigation](#mw-head)
		[Jump to search](#searchInput)
		You do not have permission to edit this page, for the following reason:

The action you have requested is limited to users in the group: [Users](/index.php?title=DreamFactory_Wiki:Users&action=edit&redlink=1).---

You can view and copy the source of this page.

{{#seo:
|title=Querying and Filtering - DreamFactory Documentation
|title_mode=replace
|description=Query, filter, sort, and paginate database records using DreamFactory's REST API parameters and operators.
|keywords=DreamFactory, query, filter, sort, paginate, REST API, database, parameters
|canonical=https://wiki.dreamfactory.com/Querying_Filtering
|og:title=Querying and Filtering
|og:type=article
|og:site_name=DreamFactory Documentation
|og:description=Query, filter, sort, and paginate database records using DreamFactory's REST API parameters and operators.
}}
'''Learn how to query, filter, sort, and paginate database records using DreamFactory's REST API'''

&lt;span id="querying-and-filtering-records-in-dreamfactory">&lt;/span>
== Querying and Filtering Records in DreamFactory ==

&lt;span id="quick-reference">&lt;/span>
== Quick Reference ==

{| class="wikitable"
|-
! Parameter
! Purpose
! Example
|-
| &lt;code>filter&lt;/code>
| Filter records
| &lt;code>filter=(status='active')&lt;/code>
|-
| &lt;code>fields&lt;/code>
| Select columns
| &lt;code>fields=id,name,email&lt;/code>
|-
| &lt;code>limit&lt;/code>
| Max records
| &lt;code>limit=10&lt;/code>
|-
| &lt;code>offset&lt;/code>
| Skip records
| &lt;code>offset=20&lt;/code>
|-
| &lt;code>order&lt;/code>
| Sort results
| &lt;code>order=name ASC&lt;/code>
|-
| &lt;code>include_count&lt;/code>
| Get total count
| &lt;code>include_count=true&lt;/code>
|-
| &lt;code>ids&lt;/code>
| Get by IDs
| &lt;code>ids=1,2,3&lt;/code>
|}

&lt;span id="overview">&lt;/span>
== Overview ==

DreamFactory provides powerful filtering capabilities for database operations, allowing you to precisely query and manipulate your data through the REST API. This guide will walk you through the basics and advanced features of filtering in DreamFactory.

&lt;span id="basic-usage">&lt;/span>
== Basic Usage ==

&lt;span id="endpoint-structure">&lt;/span>
=== Endpoint Structure ===

&lt;syntaxhighlight lang="http">GET https://{your-dreamfactory-url}/api/v2/{api_name}/_table/{table_name}?filter={filter_string}&lt;/syntaxhighlight>
{| class="wikitable"
|-
! Component
! Description
! Example
|-
| &lt;code>api_name&lt;/code>
| Name of your API service
| &lt;code>mysql&lt;/code>, &lt;code>postgres&lt;/code>
|-
| &lt;code>table_name&lt;/code>
| Database table to query
| &lt;code>customers&lt;/code>, &lt;code>orders&lt;/code>
|-
| &lt;code>filter_string&lt;/code>
| URL-encoded filter expression
| &lt;code>(status='active')&lt;/code>
|}

Your HTTP client will automatically handle URL encoding of special characters in the filter string.
&lt;span id="quick-examples">&lt;/span>
=== Quick Examples ===

&lt;syntaxhighlight lang="http"># Basic filtering
GET /api/v2/db/_table/users?filter=(status='active')

# Multiple conditions
GET /api/v2/db/_table/orders?filter=(status='pending') AND (total>100)

# Pagination and sorting
GET /api/v2/db/_table/products?limit=10&amp;offset=0&amp;order=name ASC&lt;/syntaxhighlight>
&lt;span id="filter-syntax">&lt;/span>
== Filter Syntax ==

DreamFactory uses SQL-like syntax for filtering. Ensure you are familiar with SQL operators and their usage in DreamFactory.
&lt;span id="logical-operators">&lt;/span>
=== Logical Operators ===

{| class="wikitable"
|-
! Operator
! Description
! Example
|-
| &lt;code>AND&lt;/code>
| Both conditions must be true
| &lt;code>(status='active') AND (age&amp;gt;21)&lt;/code>
|-
| &lt;code>OR&lt;/code>
| Either condition must be true
| &lt;code>(status='active') OR (status='pending')&lt;/code>
|-
| &lt;code>NOT&lt;/code>
| Negates the condition
| &lt;code>NOT(status='deleted')&lt;/code>
|}

&lt;span id="comparison-operators">&lt;/span>
=== Comparison Operators ===

{| class="wikitable"
|-
! Operator
! Description
! Example
|-
| &lt;code>=&lt;/code>, &lt;code>!=&lt;/code>
| Equality/Inequality
| &lt;code>(status = 'active')&lt;/code>
|-
| &lt;code>&amp;gt;&lt;/code>, &lt;code>&amp;gt;=&lt;/code>
| Greater than (or equal)
| &lt;code>(age &amp;gt; 21)&lt;/code>
|-
| &lt;code>&amp;lt;&lt;/code>, &lt;code>&amp;lt;=&lt;/code>
| Less than (or equal)
| &lt;code>(price &amp;lt; 100)&lt;/code>
|-
| &lt;code>IN&lt;/code>
| Match any value in set
| &lt;code>(status IN ('active','pending'))&lt;/code>
|-
| &lt;code>LIKE&lt;/code>
| Pattern matching
| &lt;code>(email LIKE '%@company.com')&lt;/code>
|-
| &lt;code>IS NULL&lt;/code>
| Check for null values
| &lt;code>(phone IS NULL)&lt;/code>
|-
| Range check
| Value in range
| &lt;code>(age&amp;gt;=18) AND (age&amp;lt;=65)&lt;/code>
|}

&lt;span id="string-operations">&lt;/span>
=== String Operations ===

{{Note|title=Database Compatibility The &lt;code>CONTAINS&lt;/code>, &lt;code>STARTS WITH&lt;/code>, and &lt;code>ENDS WITH&lt;/code> operators have limited database support. For maximum compatibility across all databases (MySQL, PostgreSQL, SQL Server, etc.), use the &lt;code>LIKE&lt;/code> operator with wildcards instead. :::|{| class="wikitable"
|-
! Operator
! Description
! Example
! Recommended Alternative
|-
| &lt;code>CONTAINS&lt;/code>
| Contains string
| &lt;code>(description CONTAINS 'important')&lt;/code>
| &lt;code>(description LIKE '%important%')&lt;/code>
|-
| &lt;code>STARTS WITH&lt;/code>
| Begins with string
| &lt;code>(name STARTS WITH 'App')&lt;/code>
| &lt;code>(name LIKE 'App%')&lt;/code>
|-
| &lt;code>ENDS WITH&lt;/code>
| Ends with string
| &lt;code>(file ENDS WITH '.pdf')&lt;/code>
| &lt;code>(file LIKE '%.pdf')&lt;/code>
|}

&lt;span id="common-filter-examples">&lt;/span>
=== Common Filter Examples ===

&lt;syntaxhighlight lang="http"># Name filters
GET /api/v2/db/_table/contacts?filter=(first_name='John') AND (last_name='Smith')
GET /api/v2/db/_table/contacts?filter=(first_name='John') OR (first_name='Jane')
GET /api/v2/db/_table/contacts?filter=first_name!='John'

# Pattern matching
GET /api/v2/db/_table/contacts?filter=first_name like 'J%'
GET /api/v2/db/_table/contacts?filter=email like '%@mycompany.com'

# Numeric comparisons
GET /api/v2/db/_table/users?filter=(age >= 30) AND (age &lt; 40)

# Social media handles
GET /api/v2/db/_table/contacts?filter=(twitter like '%jon%') OR (skype like '%jon%')&lt;/syntaxhighlight>
&lt;span id="advanced-features">&lt;/span>
== Advanced Features ==

&lt;span id="field-selection-and-metadata">&lt;/span>
=== Field Selection and Metadata ===

''Allows you to specify which fields to return in the response, reducing the amount of data transferred and improving performance. You can also include metadata such as record count and schema information.''

&lt;syntaxhighlight lang="http"># Select specific fields
GET /api/v2/db/_table/users?fields=id,name,email

# Include record count
GET /api/v2/db/_table/users?include_count=true

# Include schema information
GET /api/v2/db/_table/users?include_schema=true&lt;/syntaxhighlight>
&lt;span id="pagination-and-sorting">&lt;/span>
=== Pagination and Sorting ===

''Allows you to control the number of records returned and the order in which they are displayed.''

&lt;syntaxhighlight lang="http"># Paginate results
GET /api/v2/db/_table/users?limit=10&amp;offset=20

# Sort results
GET /api/v2/db/_table/users?order=name ASC

# Group results
GET /api/v2/db/_table/users?group=category&lt;/syntaxhighlight>
&lt;span id="related-record-filtering">&lt;/span>
=== Related Record Filtering ===

''Allows you to filter records based on values in related tables.''

&lt;syntaxhighlight lang="http"># Filter by related table
GET /api/v2/db/_table/orders?filter=(customer.country='USA')

# Filter with nested conditions
GET /api/v2/db/_table/products?filter=(category.name CONTAINS 'Electronics')&lt;/syntaxhighlight>
&lt;span id="aggregate-functions">&lt;/span>
=== Aggregate Functions ===

''Allows you to perform calculations on data, such as counting records or calculating averages, directly within the query.''

&lt;syntaxhighlight lang="http"># Count records by status
GET /api/v2/db/_table/orders?group=status&amp;fields=status,COUNT(*)

# Calculate averages
GET /api/v2/db/_table/products?fields=category,AVG(price)&lt;/syntaxhighlight>
&lt;span id="parameter-replacement">&lt;/span>
=== Parameter Replacement ===

''Allows you to use placeholders for values, which are replaced with actual values at runtime.''

&lt;syntaxhighlight lang="http">GET /api/v2/db/_table/users?filter=status=:status_param

# Request Body
{
    "params": {
        ":status_param": "active"
    }
}&lt;/syntaxhighlight>}}tip Security Best Practice Always use parameter replacement to prevent SQL injection attacks. This ensures that user input is safely handled. :::

&lt;span id="batch-operations">&lt;/span>
=== Batch Operations ===

''Allows you to handle multiple records in a single call, with options to continue processing after failures or roll back all changes if any operation fails.'' | Parameter | Description | Example | |———–|————-|———| | &lt;code>continue&lt;/code> | Continue processing after failures | &lt;code>continue=true&lt;/code> | | &lt;code>rollback&lt;/code> | Rollback all changes if any operation fails | &lt;code>rollback=true&lt;/code> |

&lt;span id="record-identification">&lt;/span>
=== Record Identification ===

&lt;syntaxhighlight lang="http"># Get by single ID
GET /api/v2/db/_table/users/123

# Get by multiple IDs
GET /api/v2/db/_table/users?ids=1,2,3

# Get by custom ID field
GET /api/v2/db/_table/users?id_field=email&amp;ids=user@example.com&lt;/syntaxhighlight>
&lt;span id="best-practices">&lt;/span>
== Best Practices ==

# '''Use Parameters''': Enhance security with parameter replacement
# '''Limit Results''': Always paginate large datasets
# '''Select Fields''': Only request needed fields
# '''URL Encoding''': Properly encode special characters
# '''Error Handling''': Use &lt;code>rollback=true&lt;/code> for critical operations
# '''Test Incrementally''': Build complex filters step by step
# '''Wrap Conditions''': Always wrap logical conditions in parentheses
# '''Validate Schema''': Use &lt;code>include_schema=true&lt;/code> to verify field names

&lt;span id="troubleshooting">&lt;/span>
== Troubleshooting ==

&lt;span id="common-issues">&lt;/span>
=== Common Issues ===

* Wrap all logical conditions in parentheses
* Use proper quotes for string values
* Verify field names with &lt;code>include_schema=true&lt;/code>
* Test complex filters incrementally

&lt;span id="response-format">&lt;/span>
=== Response Format ===

&lt;syntaxhighlight lang="json">{
    "resource": [
        {
            "id": 1,
            "name": "Example"
        }
    ],
    "meta": {
        "count": 1,
        "schema": {
            "name": "table_name",
            "fields": [...]
        }
    }
}&lt;/syntaxhighlight>
Date/time formats can be configured globally in your DreamFactory configuration. Detailed documentation is available [[getting-started/dreamfactory-configuration/date-and-time-configuration|here]].

== See also ==
* [[Generating_Database_Backed_Api|Generating a Database-backed API]]
* [[Sql_Server|Microsoft SQL Server]]

[[Category:Database_Query]]
[[Category:Api_Filtering]]
[[Category:Rest_Api_Query]]
[[Category:API]]
[[Category:Database]]
[[Category:Difficulty_Intermediate]]

[[Category:API]]
[[Category:Database]]
Template used on this page:

- [Template:Note](/Template:Note) ([view source](/index.php?title=Template:Note&action=edit))

Return to [Querying Filtering](/Querying_Filtering).

Retrieved from "[https://wiki.dreamfactory.com/Querying_Filtering](https://wiki.dreamfactory.com/Querying_Filtering)"