---
schema_version: "1"
id: 305ff1ad94dfd9c12d077af4816ab6ebb61f2acd8186773d6ca4532c2bcfb8f5
title: SQL vs SAQL
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_sql/guides/bi-sql-vs-saql.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-sql/guide/bi-sql-vs-saql.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: c1afffc0f5564c3e2b9d7a37c4dec7c558dd7c83ecacd999f903bfeb4c373c56
products:
  - SQL for Analytics Developer Guide
  - analytics
---

# SQL vs SAQL

SQL for CRM Analytics and Salesforce Analytics Query Language (SAQL) are both query languages intended for use with CRM Analytics. Here's a guide to their different behaviors and limitations.

You can only write SQL queries against datasets.

SQL for CRM Analytics doesn't offer support for these features available in SAQL.

- Random sampling
- Cogrouping
- SAQL functions `string_to_number()` and `toString()`. Type casting is unavailable in SQL for CRM Analytics.
- Relative date filtering, for example, `Closed_Date` in `["2 years ago".."1 day ago"]`
- Date functions such as `day_in_week()`, `date_diff()`, `now()`, `date_to_epoch()`, and `date_to_string()`tc

SQL and SAQL have the following differences in behavior.

- In a grouped query, SQL returns a group for null values in a grouped query by default.
- In SQL, counting all records in an empty dataset returns 0. In SAQL, it returns an empty response.
- In SQL, the `GROUPING()` function can take multiple arguments. In SAQL, it takes one argument only.
- SAQL’s `DateOnly` type corresponds with SQL for CRM Analytics’s `Date` type.
- SAQL’s `DateTime` and `Date` types correspond with SQL’s `Timestamp` type.
- In SQL, the `Date` and `Timestamp` types are treated as dates. In SAQL, when timezone is enabled, the `DateOnly` and `DateTime` types are treated as dates. When timezone isn’t enabled, the `DateOnly` and `DateTime` types are treated as strings.
- When columns in a `SELECT` statement have the same data types, but different aliases, `UNION ALL` in SQL returns the results in a single column. In SAQL, `union` returns all of the columns.
- If your values query (one without a grouping) includes aggregated and non-aggregated fields, SQL throws an error. SAQL handles such queries differently by taking the value of individual rows.

  In this example, `City` is a non-aggregated field. `Count` and `sum_Profit` are aggregated fields.

  This SQL query throws an error.

  ```nolang
  SELECT City AS "City", COUNT(*) AS "Count", sum(Profit) AS "sum_Profit"
  FROM "Superstore"
  LIMIT 100;
  ```

  The corresponding SAQL query yields the sum of `Profit` for each `City`.

  ```nolang
  q = load "Superstore";
  q = foreach q generate 'City' as 'City', count() as 'count', sum('Profit') as 'sum_Profit';
  ```
