SQL fundamentals are critical for any data professional. Master SQL fundamentals with this comprehensive guide covering 20 real interview questions from Amazon, Google, and Meta.
SQL Fundamentals Knowledge
SQL fundamentals (Structured Query Language) are the universal language for accessing and manipulating databases. Every data professional writes SQL daily, yet many miss deeper concepts that separate junior from senior engineers.
Unlike procedural languages where you tell HOW to do something, SQL fundamentals teach a declarative approach—you tell the database WHAT data you want, and it figures out how to retrieve it efficiently. This distinction is fundamental to mastering SQL.
The Power of Explicit Column Selection
SQL fundamentals teach that SELECT * is a critical anti-pattern. A table with 50 columns and 10M rows: SELECT * transfers 20GB (16 seconds). SELECT 2 columns transfers 1GB (0.8 seconds). That’s a 10-20x performance difference based on SQL fundamentals best practices.
WHERE Clause: SQL Fundamentals for Filtering
SQL fundamentals teach filtering at the database, not in your application. The database uses indexes and parallelization. Always apply WHERE clause filtering—it’s core SQL fundamentals.
NULL: The Silent Killer
SQL fundamentals include three-valued logic: TRUE, FALSE, NULL. WHERE email = NULL returns no rows because NULL = NULL evaluates to NULL, not TRUE. Use IS NULL instead. This is SQL fundamentals mistake #1 in production code.
SQL Fundamentals: Execution Order
SQL fundamentals execution order: FROM → WHERE → SELECT → ORDER BY → LIMIT. The alias created in SELECT doesn’t exist when WHERE runs. This SQL fundamentals principle explains why many queries fail.
5 Complete Interview Questions with Solutions
Question 1: GROUP BY + HAVING
Write a query: get customer_id and total_amount for customers who spent over $5000, ordered by amount descending.
SELECT customer_id, SUM(order_amount) AS total_amount FROM orders GROUP BY customer_id HAVING SUM(order_amount) > 5000 ORDER BY total_amount DESC;
Explanation: HAVING filters groups (aggregate condition). WHERE cannot filter groups. This is core SQL fundamentals.
Amazon – Senior Data AnalystFlipkart – Analytics Engineer
Question 2: NULL Handling
Find all users where email is missing OR status is ‘inactive’. Why can’t you write: WHERE email = NULL?
SELECT user_id, name, email, status FROM users WHERE email IS NULL OR status = 'inactive';
Explanation: IS NULL is correct for NULL comparisons. NULL = NULL evaluates to NULL, not TRUE, so WHERE filters it out.
Google – BI EngineerMeta – Data AnalystOYO – Senior Data Analyst
Question 3: NULL + GROUP BY + LIMIT
Return users where last_login is missing, grouped by country. Show top 5 countries by count.
SELECT country, COUNT(*) AS inactive_count FROM users WHERE last_login IS NULL GROUP BY country ORDER BY inactive_count DESC LIMIT 5;
Amazon – BI EngineerUber – Data Analyst
Question 4: Execution Order
Why fails: SELECT salary * 1.1 AS new_salary FROM employees WHERE new_salary > 50000? Fix it.
SELECT salary * 1.1 AS new_salary FROM employees WHERE salary * 1.1 > 50000;
Answer: Aliases don’t exist in WHERE. Execution order: FROM → WHERE → SELECT. Repeat the expression in WHERE.
Microsoft – Senior Data AnalystLinkedIn – Analytics EngineerUber – BI II
Question 5: Aggregates & NULL
Table has 1000 orders, 100 with NULL amount. Explain: COUNT(*) vs COUNT(amount) vs SUM(amount) vs AVG(amount).
SELECT COUNT(*) AS total_rows,
COUNT(amount) AS non_null,
SUM(amount) AS total,
AVG(amount) AS average
FROM orders;
Answer: COUNT(*)=1000, COUNT(amount)=900, SUM/AVG skip NULLs (900 values). Critical SQL fundamentals accuracy.
Google – Senior Data AnalystAirbnb – Analytics Engineer
15 Practice Questions (Test Yourself)
Test your knowledge with these 15 questions from actual company interviews. Solutions available in the complete ebook.
Question 6: You have a customers table with 50 columns. Your report only needs 3. Will SELECT * vs SELECT (3 columns) have different performance? Why?
Amazon – Senior Data AnalystMicrosoft – BI Engineer
Question 7: Write a query to find users where email is missing AND signup_date is more than 30 days old. Why must you use AND instead of OR?
Meta – Data AnalystStripe – Senior Analytics Engineer
Question 8: A query: WHERE status = ‘active’ OR status = ‘pending’ AND country = ‘USA’ returns unexpected results. Rewrite it to be unambiguous. What was the original interpretation?
Google – Senior Data AnalystAirbnb – Analytics EngineerUber – Senior Data Analyst
Question 9: You need the top 10 highest salaries. Then you need employees ranked 11-20. Which approach is slower: LIMIT 10 or OFFSET 10 LIMIT 10? Why?
LinkedIn – Senior Data AnalystFlipkart – BI Engineer
Question 10: Write a query to find customers who appear more than once in the orders table. Use GROUP BY + HAVING (not DISTINCT).
Amazon – Business Intelligence IIOYO – Senior Data Analyst
Question 11: Explain why COUNT(email) returns 900 when the table has 1000 rows with 100 NULLs in the email column.
Google – Data AnalystMeta – Senior Data AnalystAirbnb – BI Engineer
Question 12: A query uses ORDER BY salary DESC without any tiebreaker. Two employees have salary 50000. Will they appear in the same order every time you run the query?
Microsoft – Data AnalystUber – Analytics Engineer
Question 13: Write a query to calculate total_compensation (base_salary + bonus). If bonus is NULL, use 0 instead. Use COALESCE.
Amazon – Senior Data AnalystLinkedIn – Analytics Engineer
Question 14: SELECT DISTINCT customer_id returns 800 rows from 1000 orders. What can you conclude about customer distribution?
Meta – Senior Data AnalystStripe – BI EngineerOYO – Senior Data Analyst
Question 15: You need the second-highest salary without window functions or subqueries. Write the query. Then compare it to versions using subqueries and window functions.
Google – Senior Data AnalystAmazon – BI Engineer
Question 16: A query runs in 5 seconds: SELECT * FROM orders ORDER BY order_date DESC LIMIT 10. What’s likely the bottleneck? How would you debug?
Flipkart – Senior Data AnalystMicrosoft – Analytics EngineerUber – Senior Data Analyst
Question 17: Explain the difference between: WHERE column IN (‘a’, ‘b’, ‘c’) vs WHERE column = ‘a’ OR column = ‘b’ OR column = ‘c’
Meta – Data AnalystLinkedIn – Senior Data Analyst
Question 18: You write: SELECT name FROM users WHERE NOT (email = NULL). For user with NULL email, what does this return? Why?
Google – Senior Data AnalystAmazon – Business Intelligence IIAirbnb – Analytics Engineer
Question 19: Write a query to get average salary by department for departments with 10+ employees. Include employee count and salary count.
Amazon – Senior Data AnalystFlipkart – BI Engineer
Question 20: A 10 million row table takes 15 seconds with SELECT * but 2 seconds with SELECT (3 columns). Explain the actual bottleneck and calculate the data transfer difference.
Meta – Senior Data AnalystMicrosoft – Analytics EngineerUber – Senior Data Analyst
Ready to Master SQL Fundamentals & All Analytics Concepts?
These 20 practice questions are just the tip of the iceberg. To truly ace your analytics interviews and master SQL fundamentals alongside Python, statistics, machine learning, and more, get our comprehensive Data Analytics: Ace All The Interview Concepts course.
This complete guide covers everything you need to transition from junior to senior level analytics professional, including advanced SQL fundamentals, real company case studies, and interview preparation from top tech companies.
Best E-books for Real World Interview Questions
Master SQL fundamentals and advanced techniques with our comprehensive ebooks designed for data professionals preparing for top company interviews.
Complete Interview Preparation Resources
Get 2200+ Interview Questions to Become a Full Stack Analytics Professional covering SQL fundamentals, Python, Pandas, NumPy, Case Studies, Machine Learning, MS Excel, Hadoop, AWS, Statistics, and Big Data Technologies.
Specialized in Ace ANY SQL Interview – 200+ Advanced SQL Interview Questions—the ultimate guide for mastering SQL fundamentals, advanced queries, optimization techniques, and real company interview scenarios.
SQL Fundamentals Interview Preparation
Follow The Data Monk on Instagram for exclusive giveaway ebooks and interview preparation tips.
Subscribe to The Data Monk YouTube channel for company-wise interview questions, SQL fundamentals tutorials, and real-world data engineering insights.
1:1 Mentorship Program
Get personalized guidance from industry experts through our 1:1 Complete Mentorship Program. Perfect for aspiring analytics professionals looking to master SQL fundamentals and prepare for interviews at top companies like Amazon, Google, Meta, and more.
What’s included:
- 30 days of intensive mentorship and guidance
- 4 mock interviews (1 hour each)
- 4 career guidance sessions (30 mins each)
- Complete resume review and makeover
- Weekly doubts clearance sessions
- Real interview preparation materials
- Career referral opportunities