SQL Server
SELECT o.id, o.total FROM orders AS o WHERE o.total > 100;
AS is optional for tables and columns. The T-SQL-only form SELECT order_total = o.total also names a column.
AS is optional almost everywhere, and a syntax error in one place.
Filed under Querying
Write table aliases without AS and column aliases with AS; that parses on all five engines. The traps are Oracle, where AS before a table alias fails, and SQL Server's alias = expression form, which no other engine accepts.
All five engines accept FROM orders o; four also accept FROM orders AS o. Oracle rejects AS before a table alias. Column aliases accept AS everywhere, and SQL Server adds its own alias = expression form.
SELECT o.id, o.total FROM orders AS o WHERE o.total > 100;
AS is optional for tables and columns. The T-SQL-only form SELECT order_total = o.total also names a column.
SELECT o.id, o.total FROM orders o WHERE o.total > 100;
AS is optional. A column alias written without AS can't be a reserved keyword, so SELECT 1 AS from works and SELECT 1 from does not.
SELECT o.id, o.total FROM orders o WHERE o.total > 100;
AS is optional. Column aliases may be quoted with backticks, double quotes or even single quotes ('Order Total').
SELECT o.id, o.total FROM orders o WHERE o.total > 100;
AS is optional. SQLite also lets a SELECT-list alias be used in WHERE, which no other engine here allows.
SELECT o.id, o.total FROM orders o WHERE o.total > 100;
FROM orders AS o fails with a syntax error. Column aliases may use AS or omit it.
Most likely the AS in FROM orders AS o: Oracle accepts AS only for column aliases. Write FROM orders o and the query runs on every engine.
Not portably. SQL Server, PostgreSQL, MySQL and Oracle reject it because WHERE is evaluated before the SELECT list; SQLite allows it. All five accept aliases in ORDER BY, and MySQL, PostgreSQL, SQLite and Oracle 23ai also in GROUP BY. Elsewhere, repeat the expression or wrap the query in a subquery or CTE.
On derived tables in SQL Server and MySQL: FROM (SELECT …) AS x. PostgreSQL 16+, SQLite and Oracle accept an unnamed subquery, but naming it is portable. You also need aliases when the same table appears twice, as in a self-join.
WITH works in all five engines; the details around it don't.
SQL Server says SELECT INTO, three engines say CREATE TEMP TABLE AS, and Oracle needs a special prefix.
Five engines, two spellings of "give me rows 21 to 30", plus Oracle's old ROWNUM wrapper.
SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.