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
LIMITandTOPsyntax - Case-insensitive by default
- Supports
QUALIFYclause for window function filtering
BigQuery:
- Uses
LIMIT(notTOP) - Requires backticks for reserved keywords
- Supports
QUALIFYclause
Databricks:
- Supports both
LIMITandTOP - 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 | country | |
|---|---|---|---|
1 | John | USA | |
2 | Maria | Spain | |
3 | Sarah | USA | |
4 | Ahmed | Egypt |
Result:
first_name | country | |
|---|---|---|
John | USA | |
Sarah | 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 | country | |
|---|---|---|---|
1 | John | USA | |
2 | Maria | Spain | |
3 | Sarah | USA | |
4 | Bob | USA | |
5 | Carlos | 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
LIMITfor 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.