Bird
Raised Fist0
SnowflakeHow-ToBeginner · 3 min read

How to Write SELECT Statements in Snowflake: Syntax and Examples

In Snowflake, use the SELECT statement to retrieve data from tables by specifying columns and the table name. The basic syntax is SELECT column1, column2 FROM table_name; to get data from the specified columns.
📐

Syntax

The SELECT statement in Snowflake is used to fetch data from one or more columns in a table. You specify the columns you want to see, followed by the table name after FROM. You can also use * to select all columns.

  • SELECT: keyword to start the query
  • column1, column2: list of columns to retrieve
  • FROM: keyword to specify the table
  • table_name: the table to query
  • ;: ends the statement
sql
SELECT column1, column2 FROM table_name;
💻

Example

This example shows how to select the id and name columns from a table called employees. It retrieves all rows with those columns.

sql
SELECT id, name FROM employees;
Output
id | name ---|------- 1 | Alice 2 | Bob 3 | Carol
⚠️

Common Pitfalls

Common mistakes include forgetting the semicolon at the end, misspelling column or table names, or using SELECT * without knowing the table structure which can return unnecessary data.

Also, Snowflake is case-insensitive for keywords but case-sensitive for quoted identifiers.

sql
/* Wrong: missing semicolon */
SELECT id, name FROM employees

/* Right: with semicolon */
SELECT id, name FROM employees;
📊

Quick Reference

ClauseDescription
SELECTSpecifies columns to retrieve
FROMSpecifies the table to query
WHEREFilters rows based on conditions
ORDER BYSorts the result set
LIMITLimits the number of rows returned
✅

Key Takeaways

Use SELECT followed by column names and FROM table to query data in Snowflake.
Always end your SQL statements with a semicolon to avoid errors.
Use SELECT * only when you need all columns, otherwise specify columns for better performance.
Check spelling and case sensitivity for table and column names.
Use WHERE and ORDER BY clauses to filter and sort your results.