SNOWFLAKE SQL INTERVIEW QUESTIONS – QUICK NOTES
- What is Snowflake? Snowflake is a cloud-based data warehouse that separates compute and storage, allowing both to scale independently.
Key Features:
• Cloud-native architecture
• Separation of Compute & Storage
• Virtual Warehouses
• Time Travel
• Zero-Copy Cloning
• Secure Data Sharing
• Automatic Scaling
- Explain Snowflake Architecture.
Snowflake has three layers:
-
Database Storage Layer
- Stores compressed data.
-
Compute Layer
- Virtual Warehouses execute SQL queries.
-
Cloud Services Layer
- Handles authentication, metadata, query optimization, and security.
- What is a Virtual Warehouse?
A Virtual Warehouse is a compute cluster that executes SQL queries. Multiple warehouses can access the same data simultaneously.
- Difference between CTE and Subquery
CTE
- Easier to read
- Can be reused
- Supports recursive queries
Subquery
- Less readable for complex queries
- Usually used once
- Cannot be reused easily
- Types of Joins
• INNER JOIN
• LEFT JOIN
• RIGHT JOIN
• FULL OUTER JOIN
• CROSS JOIN
• SELF JOIN
- Window Functions
Common functions:
• ROW_NUMBER()
• RANK()
• DENSE_RANK()
• LAG()
• LEAD()
• SUM() OVER()
• AVG() OVER()
Example:
SELECT employee_id,
salary,
ROW_NUMBER() OVER(ORDER BY salary DESC) AS rn
FROM employees;
- QUALIFY Clause (Snowflake Specific)
Filters rows after applying window functions.
Example:
SELECT *
FROM employees
QUALIFY ROW_NUMBER() OVER
(PARTITION BY department ORDER BY salary DESC)=1;
- Difference between ROW_NUMBER(), RANK(), and DENSE_RANK()
ROW_NUMBER()
- Assigns unique numbers.
- No duplicates.
RANK()
- Same rank for ties.
- Skips rank numbers.
DENSE_RANK()
- Same rank for ties.
- Does not skip numbers.
- Find Second Highest Salary
SELECT salary
FROM employees
QUALIFY DENSE_RANK() OVER(ORDER BY salary DESC)=2;
- What is Time Travel?
Allows recovery of deleted or modified data within the configured retention period.
- What is Zero Copy Cloning?
Creates an instant copy of tables, schemas, or databases without duplicating physical storage.
- Temporary vs Transient vs Permanent Tables
Temporary Table
- Exists only for the current session.
Transient Table
- No Fail-safe.
- Lower storage cost.
Permanent Table
- Supports Time Travel and Fail-safe.
Common SQL Interview Questions
Find duplicate records.
Remove duplicate records.
Find the second highest salary.
Find the top 3 salaries in each department.
Calculate running totals.
Calculate rolling averages.
Find employees earning above department average.
Get the latest record for each customer.
Count customers by month.
Find missing dates.
- Performance Tips
• Avoid SELECT *.
• Filter data as early as possible.
• Use appropriate warehouse size.
• Use clustering keys when necessary.
• Use QUALIFY instead of nested subqueries where applicable.
- Frequently Asked Snowflake Questions
• What are Micro-partitions?
• Explain Snowpipe.
• What are Streams and Tasks?
• What is Fail-safe?
• Difference between COPY INTO and Snowpipe.
• What is VARIANT data type?
• Explain FLATTEN().
• Explain RBAC in Snowflake.
• How do you optimize slow queries?
• What is Query Profile?
Interview Tips
✔ Master Joins, CTEs, Window Functions, and QUALIFY.
✔ Practice writing SQL without an editor.
✔ Learn Snowflake-specific features:
- Time Travel
- Zero-Copy Cloning
- Streams
- Tasks
- Snowpipe
- VARIANT
- FLATTEN
- Virtual Warehouses
✔ Explain your SQL logic clearly during the interview.
Top comments (0)