dataengref migrate

Home / SQL Server

SQL Server TOP in Snowflake, Databricks and BigQuery

Snowflake accepts SELECT TOP n. Databricks and BigQuery use LIMIT n at the end of the query. TOP n PERCENT and WITH TIES have no direct equivalent in any of them.

SQL Server syntax: SELECT TOP (expression) [PERCENT] [WITH TIES] ... · SQL Server docs

Equivalents

TargetSupportSyntaxNotesSource
SnowflakeSame nameSELECT TOP n ...TOP n and LIMIT n are equivalent in Snowflake.Snowflake docs
DatabricksRewriteSELECT ... LIMIT nLIMIT goes at the end of the query.Databricks docs
BigQueryRewriteSELECT ... LIMIT nLIMIT goes at the end of the query; OFFSET is optional.BigQuery docs

Behavior differences to check

Examples

Ten most recent orders

SQL Server
SELECT TOP 10 order_id, ordered_at FROM orders ORDER BY ordered_at DESC;
Snowflake
SELECT TOP 10 order_id, ordered_at FROM orders ORDER BY ordered_at DESC;
Databricks
SELECT order_id, ordered_at FROM orders ORDER BY ordered_at DESC LIMIT 10;
BigQuery
SELECT order_id, ordered_at FROM orders ORDER BY ordered_at DESC LIMIT 10;

Other SQL Server functions

Last checked: · Paste a whole query into the SQL checker to find every function that needs a change.