Español Practice SQL

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

DatabaseFirst 5 rows
SQL ServerSELECT TOP 5 ... ORDER BY ...
OracleORDER BY ... FETCH FIRST 5 ROWS ONLY
PostgreSQLORDER BY ... LIMIT 5
SnowflakeORDER BY ... LIMIT 5 (TOP also works)

Empty values

DatabaseFill NULL
SQL ServerISNULL(x, y) or COALESCE
OracleNVL(x, y) or COALESCE
PostgreSQLCOALESCE only
SnowflakeNVL, 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

DatabaseAdd 30 daysDays between
SQL ServerDATEADD(day, 30, d)DATEDIFF(day, a, b)
Oracled + 30b - a
PostgreSQLd + INTERVAL '30 days'b - a
SnowflakeDATEADD(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

Guides for this article

More articles