SQL Subqueries Explained: Filtering, Comparing, and Calculating Data

🚀 SQL Journey – Day 22: Subqueries in SQL Today I explored one of the most powerful concepts in SQL — Subqueries 🔍 💡 What I learned: • A subquery is a query inside another query • Helps to filter, compare, and calculate data efficiently 📊 Types of Subqueries: • Single Row, Multiple Row, Multiple Column • Based on Dependency → Independent & Correlated • Based on Location → SELECT, WHERE, FROM • Based on Keywords → IN, ANY, ALL, EXISTS 🔥 Highlight of the day — Correlated Subquery: • Depends on the outer query • Executes row by row • Useful for comparing values within groups 💻 Example: Find employees earning more than their department average SELECT e1.name, e1.salary FROM employees e1 WHERE e1.salary > ( SELECT AVG(e2.salary) FROM employees e2 WHERE e2.dept_id = e1.dept_id ); 🎯 Key Takeaway: Subqueries make SQL smarter with nested logic, and correlated subqueries take it further with row-level comparisons. #SQL #DataAnalytics #LearningJourney #SQLPractice #ITProjects #DataEngineering

  • graphical user interface, text, application, chat or text message

To view or add a comment, sign in

Explore content categories