SELECT

Category: Data Query Language (DQL)

Platform Support:

✅ Snowflake | ✅ BigQuery | ✅ Databricks

Description

The SELECT statement retrieves data from one or more tables in a database. It's the most fundamental and commonly used SQL command for querying data.

Syntax

SELECT column1, column2, ...
FROM table_name
[WHERE condition]
[GROUP BY column]
[HAVING condition]
[ORDER BY column]
[LIMIT n];

Platform-Specific Notes

Snowflake:

  • Supports LIMIT and TOP syntax
  • Case-insensitive by default
  • Supports QUALIFY clause for window function filtering

BigQuery:

  • Uses LIMIT (not TOP)
  • Requires backticks for reserved keywords
  • Supports QUALIFY clause

Databricks:

  • Supports both LIMIT and TOP
  • Case-insensitive by default
  • Does not support QUALIFY (use subquery instead)

Example 1: Basic SELECT

SELECT first_name, email, country
FROM customers
WHERE country = 'USA';

Sample Data (customers table):

id

first_name

email

country

1

John

john@email.com

USA

2

Maria

maria@email.com

Spain

3

Sarah

sarah@email.com

USA

4

Ahmed

ahmed@email.com

Egypt

Result:

first_name

email

country

John

john@email.com

USA

Sarah

sarah@email.com

USA

Example 2: SELECT with Aggregation

All Platforms:

SELECT 
    country,
    COUNT(*) as customer_count,
    COUNT(DISTINCT email) as unique_emails
FROM customers
GROUP BY country
ORDER BY customer_count DESC;

Sample Data:

id

first_name

email

country

1

John

john@email.com

USA

2

Maria

maria@email.com

Spain

3

Sarah

sarah@email.com

USA

4

Bob

bob@email.com

USA

5

Carlos

carlos@email.com

Spain

Result:

country

customer_count

unique_emails

USA

3

3

Spain

2

2

Best Practices

  • Always specify column names explicitly rather than using SELECT * in production code
  • Use aliases for better readability
  • Add LIMIT for exploratory queries on large tables
  • Consider using QUALIFY (Snowflake/BigQuery) for filtering window functions

Interested to Learn More? Try Out the Free 14-Days Trial

One AI-native workspace to build, ship, and monitor dbt™ — without the tool sprawl.