SQL Server, Oracle, PostgreSQL and Snowflake syntax differences
Most SQL is the same everywhere. A short list of things is not, and those are exactly what slows you down in a new job.
Top rows
| Database | First 5 rows |
|---|---|
| SQL Server | SELECT TOP 5 ... ORDER BY ... |
| Oracle | ORDER BY ... FETCH FIRST 5 ROWS ONLY |
| PostgreSQL | ORDER BY ... LIMIT 5 |
| Snowflake | ORDER BY ... LIMIT 5 (TOP also works) |
Empty values
| Database | Fill NULL |
|---|---|
| SQL Server | ISNULL(x, y) or COALESCE |
| Oracle | NVL(x, y) or COALESCE |
| PostgreSQL | COALESCE only |
| Snowflake | NVL, IFNULL or COALESCE |
COALESCE works in all four. If you write SQL that others will move between systems, use it.
Case insensitive search
LIKE ignores case in a default SQL Server, but not in Oracle, PostgreSQL or Snowflake. PostgreSQL and Snowflake have ILIKE; in Oracle compare LOWER(column) with a lowercase pattern.
Dates
| Database | Add 30 days | Days between |
|---|---|---|
| SQL Server | DATEADD(day, 30, d) | DATEDIFF(day, a, b) |
| Oracle | d + 30 | b - a |
| PostgreSQL | d + INTERVAL '30 days' | b - a |
| Snowflake | DATEADD(day, 30, d) | DATEDIFF(day, a, b) |
The dialect tracks in the practice cover each of these. You write the query in the syntax of your database, and if you use something that database does not have, the checker tells you what to write instead.
Practice what you just read
Open the practice