---
schema_version: "1"
id: d676ef926938b8a1425015d71fab69f0a727e1d6808cdd59fd0c97a8c903abda
title: Check Whether Related Data Exists by Using Subqueries
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/data-cloud-query-guide/guides/get-started-dc-sql/subqueries-related-data.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-query-guide/guide/subqueries-related-data.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: df7ce11be76d6e9b97aa314b82d497e7af5e94b5047d02cfdc22528b5395f2a0
products:
  - Data 360 Query Guide
  - Data 360 Developer Documentation
---
# Check Whether Related Data Exists by Using Subqueries

To check for the presence or absence of related data, use the `EXISTS` or `NOT EXISTS` operators. These operators are part of the `WHERE` clause that precedes a subquery. A subquery is a query that appears inside another query statement.

These query examples all use a subquery to check on related records to accounts.

- Which accounts don’t have a phone number?
- Which accounts have a phone number but no email address?
- How many accounts have a phone number but no email address?

For example, this query uses a subquery to return the accounts that don’t have a phone number.

```
SELECT "ssot__Id__c",
       "ssot__Name__c"
FROM "ssot__Account__dlm"
WHERE NOT EXISTS (
 SELECT *
      FROM "ssot__ContactPointPhone__dlm"
 WHERE "ssot__ContactPointPhone__dlm"."ssot__PartyId__c" = "ssot__Account__dlm"."ssot__Id__c"
)

```

This output shows the first few rows of the sample results.

| `ssot__Id__c`      | `ssot__Name__c`             |
| ------------------ | --------------------------- |
| 001Hu00002xHZJnIAO | Pyramid Construction Inc.   |
| 001Hu00002xHZJtIAO | United Oil & Gas, UK        |
| 001Hu00002xHZJuIAO | United Oil & Gas, Singapore |

You can use these predicates with subqueries.

- `EXISTS`
- `NOT EXISTS`
- `IN`
