---
schema_version: "1"
id: 490928df990765e6257e97d2855784c0fced4ff43405f3c64b7404307b233677
title: null Values in Lookup Relationships and Outer Joins
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-soql-sosl/guides/soql-sosl/sforce-api-calls-soql-relationships-lookup.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-soql-sosl/guide/sforce-api-calls-soql-relationships-lookup.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: ad6f13c261f91381fe386999d591e3e95bbb9a0eebfc5cb4820e2b005627ee8f
products:
  - SOQL and SOSL Reference
  - Platform Developer Content
---

# `null` Values in Lookup Relationships and Outer Joins

Relationship SOQL queries return records, even if the relevant foreign key field has a null value, as with an outer join.

- In an `ORDER BY` clause, the record is returned even if the foreign key value in a record is null. For example:

  <!-- otherprops: soql -->

  ```codesegment
  SELECT Id, CaseNumber, Account.Id, Account.Name
  FROM Case
  ORDER BY Account.Name
  ```

  Any case record for which `AccountId` is empty is returned.

  The following example uses custom objects:

  <!-- otherprops: soql -->

  ```codesegment
  SELECT ID, Name, Parent__r.id, Parent__r.name
  FROM Child__c
  ORDER BY Parent__r.name
  ```

  This query returns the `Id` and `Name` values of the Child object and the `Id` and name of the Parent object referenced in each Child, and orders the results by the parent name. Records are returned even if `Parent__r.id` or `Parent__r.name` are null.

- In a `WHERE` clause that uses `OR`, records are returned even if the foreign key value in a record is null. For example, if your organization has one contact with the value of its `LastName` field equal to `Young` and the value of its `AccountId` field equal to `null`, and another contact with a different last name and a parent account named `Quarry`, the following query returns both contacts:

  <!-- otherprops: soql -->

  ```codesegment
  SELECT Id FROM Contact WHERE LastName = 'Young' or Account.Name = 'Quarry'
  ```

- In a `WHERE` clause that checks for a value in a parent field, the record is returned even if the parent does not exist.. For example:

  ```soql
  SELECT Id
  FROM Case
  WHERE Contact.LastName = null
  ```

  Case record `Id` values are returned.

- In a `WHERE` clause that uses a Boolean field, the Boolean field never has a null value. Instead, `null` is treated as `false`. Boolean fields on outer-joined objects are treated as false when no records match the query.
