Using SOQL queries with the ODBC driver
Last modified: July 7, 2025
You can query Salesforce data using either SQL or SOQL, Salesforce’s native query language designed specifically for querying its object-based data model.
The main difference between SQL and SOQL is how they handle data filtering, which directly impacts performance:
-
SOQL: Data is filtered on the server side.
Only records that meet the query conditions are returned to the client machine. This reduces network load and results in faster response times—especially important when working with large datasets in the Salesforce cloud environment. -
SQL: Data is filtered on the client side.
SQL queries often retrieve a larger set of data from the server, then apply filters andJOIN
operations on the client machine. This can increase the amount of data sent over the network and potentially degrade performance.
While SOQL provides better performance through server-side filtering, it has a simpler syntax and is limited to read-only operations. SOQL doesn’t support JOIN
, wildcard field selection, or data modification statements like INSERT
, UPDATE
, or DELETE
. In contrast, SQL supports all of these features, making it better suited for complex queries, though its flexibility can come at the cost of performance in cloud-based environments like Salesforce.
The following table outlines the main differences between SOQL and SQL.
Feature | SOQL | SQL |
---|---|---|
Data operations | Supports only data retrieval (no INSERT , UPDATE , DELETE ). |
Supports INSERT , UPDATE , DELETE . |
Field selection | No wildcard selection—all fields must be explicitly listed. | Supports SELECT . |
Relationships | Supports object relationships (parent-to-child and child-to-parent). | Supports JOIN . |
Query scope | Queries only related Salesforce objects. | Queries multiple unrelated tables. |
Performance | Faster–filtering happens on the server before data is sent. | Slower—data is sent first, then filtered on the client. |
When you write queries in SOQL, they bypass the automatic translation from SQL to SOQL.
For more information about SQL-to-SOQL translation, see SQL Translation.
For more information on SOQL syntax, see Salesforce Object Query Language (SOQL).
Querying Salesforce database
A SOQL query must be prefixed with SOQL:
to ensure it’s processed as SOQL.
SOQL:SELECT Contact.FirstName, Contact.Account.Name FROM Contact
To retrieve related records, use object relationships instead of the JOIN
keyword.
The following queries retrieve the same fields—contact name, email, and associated account name—using different approaches.
-
SQL: Uses a
LEFT JOIN
to link theContact
andAccount
tables based onAccountId
field.SELECT Contact.Name, Contact.Email, Account.Name FROM Contact LEFT JOIN Account ON (Contact.AccountId = Account.Id)
-
SOQL: Accesses the
Account.Name
field using the predefined relationship between theContact
object and its associatedAccount
object. This is known as relationship traversal—retrieving fields from a related object without using a JOIN.SOQL:SELECT Name, Email, Account.Name FROM Contact
Both return all contacts, including those without an associated account. In such cases, Account.Name
will be null.
SOQL limitations
Devart ODBC Driver for Salesforce doesn’t support SOQL subqueries that return nested collections, such as the following query.
SOQL: SELECT Account.Name, (SELECT Contact.LastName FROM Account.Contacts) FROM Account
To overcome this limitation, use one of the following approaches:
- SOQL: Query the child object (
Contact
) and reference parent fields using the relationship name.
SOQL: SELECT LastName, Account.Name FROM Contact
- SQL: Perform an equivalent
JOIN
using standard SQL syntax.
SELECT Account.Name, Contact.LastName FROM Contact, Account WHERE Account.Id = Contact.AccountId
Except for nested subqueries, the driver supports all standard SOQL queries described in the Salesforce Object Query Language (SOQL) documentation.