---
schema_version: "1"
id: 932b5bcd9d5d398576669aea5fbae7784774053b99eae3cb17ddcb7e72f83d1c
title: SQL Where Clause for Salesforce Data Recovery
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/backup_recover_o_sql_where_clause_examples.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.backup_recover_o_sql_where_clause_examples.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 21ab8007dc0ea3d0aa267a94fef1c4e84e400a1ceb652d95cf5368fcd0e19d38
description: Use SQL where clauses during recovery, repair, and restore processes to filter and select specific records. SQL where clauses give you precise control over which data is restored or repaired.
products:
  - Security
  - Salesforce Platform
release: "264"
---
# SQL Where Clause for Salesforce Data Recovery

Use SQL where clauses during recovery, repair, and restore processes to filter and select specific records. SQL where clauses give you precise control over which data is restored or repaired.

## SQL Where Clause Examples

Use SQL statements to return a collection of records that match your criteria.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-own_from_salesforce-264-0-0-production-enus/8ac98673-ede2-4046-a41e-2d5c846f24ff/images/icon_example.png)

Example

- Filter all Account records where the 'IsPartner' field is checked:
    - isPartner = 'true'
    - Note that the IsPartner field on the Account object is available only in Orgs where partner relationship management (partner portal) is enabled.
- Only keep records that have two specific Record Types:
    - RecordTypeId in ('01235000001BJrlAAW', '01215000001BJrLAAW')
- Only keep records whose name field contains the word 'acme':
    - Name LIKE '%acme%'
- Only keep records where a custom field (for example, 'Value\_\_c') is empty:
    - Value\_\_c = ''
- Only keep records that have a value between 2 values (for example, between 100 and 200):
    - cast(Value\_\_c as integer) > 100 AND cast(Value\_\_c as integer) <= 200
- Keep records that meet one of several conditions (Red, Blue or Green):
    - Color\_\_c IN ('Red', 'Blue', 'Green')
    - Color\_\_c = 'Red' OR Color\_\_c = 'Blue' OR Color\_\_C = 'Green'
- Keep records that must meet several conditions:
    - Cast(Height as integer) > 15 AND cast(Width as integer) < 5 AND cast(Depth as integer >= 10
- Keep records that do not match the provided value(s):
    - Country != 'USA'
    - Country NOT IN ('USA', 'Canada')
- Replicate Accounts based on a checkbox and bring the parent account of those accounts:
    - WHERE CopyToDev\_\_c = 'true' OR Id IN (SELECT ParentId FROM Account WHERE CopyToDev\_\_c = 'true')
- Only keep records that were created on a specific date (for example, November 27, 2017):
    - CreatedDate = '2017-11-27'
- Only keep records that were NOT created on a specific date:
    - CreatedDate != '2017-11-27'
- Find all records added after a specific date:
    - CreatedDate >; '2019-09-16T00:00:00.000Z'
        
        ![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-own_from_salesforce-264-0-0-production-enus/8ac98673-ede2-4046-a41e-2d5c846f24ff/images/icon_note.png)
        
        Note You need to update the date above to whichever date is applicable.
- Replicate a subset of record for each RecordType, for example, 5 records of each of my 3 Accounts RecordType
    - Id IN (SELECT Id FROM Account WHERE RecordTypeId='A' LIMIT 5) OR Id IN (SELECT Id FROM Account WHERE RecordTypeId='B' LIMIT 5) OR Id IN (SELECT Id FROM Account WHERE RecordTypeId='C' LIMIT 5)
- Replicate a subset of records where we have 2 Parents and related Junction Object
    - To illustrate that example, let’s consider we have Account and Survey as a Parent object and an object called Survey\_Answer that is our Junction Object.
    - On the Replicate Job, select Account and Survey.
    - Click on the gear next to Account and select a subset of date you would like.
    - Click on the gear next to the Parent Object Survey and run the following query: Id in (SELECT Survey\_\_c FROM Account$Survey\_Answer\_\_c).
    - Click on the gear of Survey\_Answer (Under the object Survey) and run the query: Id in (Select Id from Account$Survey\_Answer\_\_c).

## Considerations and Limitations when Using the SQL Where Clause

- Field values are case-sensitive e.g. Color\_\_c IN ('Red', 'red') "Red", and "red" are considered two different values.
- Field names are NOT case-sensitive, so (IsPartner = ispartner)
- Custom field names must be in the API name format; e.g. Field\_Name\_\_c
- When using the 'IN' operator with record IDs, you must use the 18-char version (not the 15 char)
- When using the 'LIKE' operator with records IDs, you can use the 15-char format, because this looks for a partial match
- The '%%' operator is NOT case-sensitive
- Performing a where clause on lookup fields requires the use of the record id as the value e.g. Lookup\_\_c = '01215000001BJrLAAW'

## Comparison Operators for the SQL Where Clause

- \= Equals
- != Not equals
- < Less than
- <= Less than or equal to
- \> Greater than
- \>= Greater than or equal to
- LIKE Like
- IN In
- NOT IN Not in