This guide provides best practices for writing well-structured SQL queries to improve readability, maintainability, and performance.
SELECT
, FROM
, WHERE
, GROUP BY
, HAVING
, ORDER BY
) on a new line.JOIN
clauses vertically when appropriate.AS
keyword.SELECT
clause when selecting multiple columns.{{DATABASE_NAME}}
.Redshift
AS
keyword. Aliases improve readability and make queries more concise.Guideline 2: Enclose Identifiers in Double Quotes ("
)Always use double quotes for column, table, and subquery names to avoid conflicts with reserved keywords and case-sensitive identifiers.Guideline 3: Reference Tables with the Database NameAlways prefix tables with the database and schema name to ensure clarity, especially in multi-schema databases.**Example Use **CaseSnowflake
AS
keyword. Aliases improve readability and make queries more concise.Guideline 2: Enclose Identifiers in Double Quotes ("
)Always use double quotes for column names to avoid conflicts with reserved keywords and case-sensitive identifiers.Guideline 3: Reference Tables with the Database NameAlways prefix tables with the database and schema name to ensure clarity, especially in multi-schema databases.Example Use CaseBigQuery
AS
keyword. Aliases improve readability and make queries more concise.Guideline 2: Enclose Identifiers in Double Quotes (`
)Always use backticks for column names to avoid conflicts with reserved keywords and case-sensitive identifiers.Guideline 3: Reference Tables with the Database NameAlways prefix tables with the database and schema name to ensure clarity, especially in multi-schema databases.MySQL
PostgreSQL
AS
keyword. Aliases improve readability and make queries more concise.Guideline 2: Enclose Identifiers in Double Quotes ("
)Always use double quotes for column, table, and subquery names to avoid conflicts with reserved keywords and case-sensitive identifiers.Guideline 3: Reference Tables with the Database NameAlways prefix tables with the database and schema name to ensure clarity, especially in multi-schema databases.Example Use CaseMongoDB
Elasticsearch
Databricks
ClickHouse
AS
) for column and table names to improve readability and simplify column references.Guideline 2: Enclose Identifiers in BackticksUse backticks around column and table names, especially if they contain spaces, special characters, or case sensitivity to avoid parsing errors.MSSQL
AS
keyword. Aliases improve readability and make queries more concise.Guideline 2: Enclose Identifiers in Double Quotes ("
)Always use double quotes for column, table, and subquery names to avoid conflicts with reserved keywords and case-sensitive identifiers.Guideline 3: Reference Tables with the Database NameAlways prefix tables with the database and schema name to ensure clarity, especially in multi-schema databases.Example Use CaseAwsS3
AS
keyword. Aliases improve readability and make queries more concise.Guideline 2: Enclose Identifiers in Double Quotes ("
)Always use double quotes for column, table, and subquery names to avoid conflicts with reserved keywords and case-sensitive identifiers.Guideline 3: Reference Tables with the Database NameAlways prefix tables with the database and schema name to ensure clarity, especially in multi-schema databases.Example Use CaseFirebolt
AS
keyword. Aliases improve readability and make queries more concise.Guideline 2: Enclose Identifiers in Double Quotes ("
)Always use double quotes for column, table, and subquery names to avoid conflicts with reserved keywords and case-sensitive identifiers.Guideline 3: Reference Tables with the Database NameAlways prefix tables with the database and schema name to ensure clarity, especially in multi-schema databases.Example Use CaseSingleStore
AS
keyword. Aliases improve readability and make queries more concise.Guideline 2: Enclose Identifiers in Backticks (`
)Database names, table names, and column names should be enclosed in backticks (`).Guideline 3: Reference Tables with the Database NameAlways prefix tables with the database and schema name to ensure clarity, especially in multi-schema databases.OpenSearch
AS
) for column and table names to improve readability and simplify column references.Guideline 2: Enclose Identifiers in BackticksUse backticks around column and table names, especially if they contain spaces, special characters, or case sensitivity to avoid parsing errors.