SELECT retrieves one or more columns from one or more Snowflake tables or views.
SELECT returns tabular data from one or more tables or views. You can choose columns, filter rows, sort results, aggregate, and join related tables all in one command.
List columns after SELECT. Use table aliases to clarify origin and avoid ambiguity in joins.
SELECT c.name, c.email, o.total_amount
FROM Customers AS c
JOIN Orders AS o ON o.customer_id = c.id;
Append WHERE with Boolean expressions. Combine conditions with AND / OR. Use placeholders for parameters in Galaxy.
SELECT id, name, price
FROM Products
WHERE price > 50 AND stock > 0;
ORDER BY arranges rows after filtering. Default is ascending; use DESC for descending.
SELECT id, order_date, total_amount
FROM Orders
ORDER BY order_date DESC;
LIMIT (or FETCH) caps returned rows. Combine with ORDER BY for deterministic results.
SELECT *
FROM Products
ORDER BY stock DESC
LIMIT 5;
Use GROUP BY with aggregate functions to summarize. HAVING filters groups after aggregation.
SELECT customer_id, COUNT(*) AS order_count, SUM(total_amount) AS revenue
FROM Orders
GROUP BY customer_id
HAVING SUM(total_amount) > 1000;
Always enumerate columns in production queries, qualify columns in joins, index frequently filtered columns, and test queries with LIMIT before full runs.
Avoid SELECT * in wide tables; it hinders performance. Don’t forget conditions in joins, or you’ll create Cartesian products.
SELECT [columns]FROM [table1] [JOIN table2 ON condition]WHERE [conditions]GROUP BY [columns]HAVING [aggregate_condition]ORDER BY [columns]LIMIT [n];
Yes. Use AS: SELECT price * quantity AS line_total FROM OrderItems;
Combine LIMIT with OFFSET: SELECT * FROM Products ORDER BY id LIMIT 20 OFFSET 40;
Yes, query results are cached for 24 hours by default, accelerating repeated identical queries.