SQL dialect gotchas
Interviewers rarely fail you for dialect syntax. But in real work, and in take-homes on a specific warehouse, a few differences silently change results. These are the ones worth knowing. Each one links to the vendor documentation, because defaults change between versions.
The playground runs DuckDB, which behaves like PostgreSQL in most of these cases.
Changes your results
| Gotcha | What happens | Docs |
|---|---|---|
| Integer division | SQL Server: 5 / 2 = 2 (integer). BigQuery: / returns FLOAT64 (2.5); use DIV for integers. Snowflake: returns a decimal with extra scale (2.500000). | SQL Server · BigQuery · Snowflake |
| Default NULL sort order | Snowflake: NULLs sort last in ascending order (configurable with DEFAULT_NULL_ORDERING). BigQuery and SQL Server: NULLs are lowest, so first in ascending order. Changes ORDER BY … LIMIT and ROW_NUMBER results. Write NULLS FIRST/LAST explicitly where supported. | Snowflake · BigQuery |
| Week start | BigQuery DATE_TRUNC(d, WEEK) starts on Sunday; use WEEK(MONDAY) or ISOWEEK. Snowflake depends on the WEEK_START parameter. | BigQuery · Snowflake |
| DATEDIFF counts boundaries | Snowflake and SQL Server DATEDIFF(minute, a, b) count minute boundaries crossed, not elapsed minutes. 10:00:59 to 10:01:00 is "1 minute". Use seconds and divide. | Snowflake · SQL Server |
| Case-sensitive comparisons | SQL Server's default collations are case-insensitive ('A' = 'a'); Snowflake compares case-sensitively by default. Joins and GROUP BYs on text change. | SQL Server |
| Timestamp types | BigQuery TIMESTAMP is an absolute instant (UTC); DATETIME has no time zone. Snowflake has TIMESTAMP_NTZ, _LTZ and _TZ, and plain TIMESTAMP maps to one of them by setting. | BigQuery · Snowflake |
Syntax that won't run elsewhere
| Gotcha | Difference | Docs |
|---|---|---|
| Row limits | SQL Server uses TOP n or OFFSET … FETCH, not LIMIT. | SQL Server |
| String concatenation | SQL Server uses + (or CONCAT); most others use ||. With +, a NULL makes the whole result NULL. | SQL Server |
| Booleans | SQL Server has no boolean column type; use BIT and compare = 1. | SQL Server |
| GROUP BY alias or position | SQL Server doesn't allow GROUP BY 1 or a SELECT alias; repeat the expression. | SQL Server |
| QUALIFY | Snowflake, BigQuery and Databricks support it; SQL Server doesn't (use a CTE). | Snowflake · BigQuery · Databricks |
| DATE_TRUNC argument order | BigQuery: DATE_TRUNC(d, MONTH). Snowflake and Databricks: DATE_TRUNC('MONTH', d). SQL Server 2022+: DATETRUNC(month, d). | BigQuery · SQL Server |
| Recursive CTEs | SQL Server omits the RECURSIVE keyword; BigQuery requires it. | SQL Server · BigQuery |
| Identifier case | Snowflake uppercases unquoted identifiers; "orderId" and orderid are different columns. | Snowflake |
Teradata
Teradata notes are being reviewed and will be added with sources. Many migration projects start from Teradata, so this section is a priority.
Practice
Most SQL questions in the bank include dialect notes with sources. Open a question's solution to see them.