SQL Practice Logo

SQLPractice Online

Cross-Database Compatibility: Functions

Module: Database-Specific Features

Portable SQL syntax rules: (1) Use ANSI SQL standard: SELECT, INSERT, UPDATE, DELETE, JOIN, GROUP BY, HAVING, ORDER BY. (2) Pagination: Use OFFSET/FETCH (SQL:2008 standard) instead of LIMIT/TOP. MySQL doesn't support OFFSET/FETCH, so use ORM or conditional SQL. (3) String concatenation: Use CONCAT() function (ANSI SQL) instead of || or +. (4) Date functions: Use CURRENT_TIMESTAMP (ANSI SQL) instead of NOW()/GETDATE()/SYSDATE. (5) Boolean: Use TINYINT(1) or BIT with 1/0 values instead of BOOLEAN with TRUE/FALSE. (6) Auto-increment: Use ORM or IDENTITY (SQL:2003 standard, not supported by MySQL). (7) Joins: Use ANSI JOIN syntax (INNER JOIN, LEFT JOIN) instead of old comma syntax. (8) Quotes: Use single quotes for strings, avoid double quotes for identifiers (not portable across databases). (9) NULL handling: Use IS NULL / IS NOT NULL, not = NULL. (10) CASE expressions: ANSI SQL, works everywhere.

Use ANSI SQL standard: SELECT, INSERT, UPDATE, DELETE, JOIN, GROUP BY, HAVING, ORDER BY (works on all databases)

Pagination: Use OFFSET/FETCH (SQL:2008 standard, not MySQL) or conditional SQL (LIMIT for MySQL, OFFSET/FETCH for others)

String concatenation: Use CONCAT() function (ANSI SQL) instead of || (PostgreSQL/Oracle) or + (SQL Server)

Date functions: Use CURRENT_TIMESTAMP (ANSI SQL) instead of NOW()/GETDATE()/SYSDATE()

Boolean: Use TINYINT(1) or BIT with 1/0 values instead of BOOLEAN with TRUE/FALSE (not portable)

Auto-increment: Use ORM or IDENTITY (SQL:2003, not MySQL) - syntax varies: AUTO_INCREMENT (MySQL), SERIAL (PostgreSQL), IDENTITY (SQL Server)

Joins: Use ANSI JOIN syntax (INNER JOIN, LEFT JOIN) instead of comma syntax (old style, less portable)

LIMIT pagination, CONCAT() for strings, AUTO_INCREMENT, no OFFSET/FETCH, no RETURNING clause

LIMIT or OFFSET/FETCH, || or CONCAT(), SERIAL or IDENTITY, RETURNING clause, advanced features (arrays, JSONB)

TOP or OFFSET/FETCH, + or CONCAT(), IDENTITY, T-SQL extensions, no LIMIT

ROWNUM or OFFSET/FETCH, || or CONCAT(), SEQUENCE, PL/SQL, expensive licensing

Core references in this topic include WHERE, =, <, >, <=, >=. Learn what each one does, when to use it, and the execution or engine rules that matter.

WHERE

Filters rows before projection and sorting. It decides which rows continue through the query pipeline.

SELECT ... FROM table WHERE condition;

Most performance issues start with a weak WHERE clause or a missing supporting index.

=

Returns rows where the left and right values are exactly equal.

column = value

Use with exact matches. Do not use = NULL.

<, >, <=, >=

Range comparison operators for less-than, greater-than, and inclusive boundary checks.

salary >= 80000

OR

Matches rows when at least one condition is TRUE.

condition_a OR condition_b

Use parentheses when mixing OR with AND.

NOT

Negates a boolean condition and returns the opposite truth value.

NOT condition

IS NULL / IS NOT NULL

Tests whether a value is missing. SQL NULL semantics require dedicated NULL predicates.

manager_id IS NULL

Never use = NULL or != NULL.

ANY / ALL

Compares one value against every or at least one value from a subquery result.

salary > ALL (SELECT salary FROM interns)

DATE

Stores a calendar date without any time-of-day component.