Savvana Lohitha’s Post

🚀 𝗦𝗤𝗟 𝗝𝗼𝘂𝗿𝗻𝗲𝘆 – 𝗗𝗮𝘆 𝟮𝟲: 𝗜𝗻𝘁𝗿𝗼𝗱𝘂𝗰𝘁𝗶𝗼𝗻 𝘁𝗼 𝗦𝘂𝗯𝗾𝘂𝗲𝗿𝗶𝗲𝘀 Today I explored one of the most powerful concepts in SQL — Subqueries 🔍 🔹 𝗪𝗵𝗮𝘁 𝗶𝘀 𝗮 𝗦𝘂𝗯𝗾𝘂𝗲𝗿𝘆? A subquery is a query inside another query used to perform intermediate calculations and filter results. 💼 𝗥𝗲𝗮𝗹-𝘄𝗼𝗿𝗹𝗱 𝗽𝗲𝗿𝘀𝗽𝗲𝗰𝘁𝗶𝘃𝗲 (𝗠𝗮𝗻𝗮𝗴𝗲𝗿’𝘀 𝗾𝘂𝗲𝘀𝘁𝗶𝗼𝗻𝘀): Which product performs well? Which store performs well? Which customers perform well? 👉 These types of questions are easily solved using subqueries by comparing individual performance with averages or totals. 🔹 𝗖𝗼𝗿𝗿𝗲𝗹𝗮𝘁𝗲𝗱 𝗦𝘂𝗯𝗾𝘂𝗲𝗿𝘆 𝗘𝘅𝗮𝗺𝗽𝗹𝗲: SELECT cid, cname, category, amt FROM cust c1 WHERE amt > (   SELECT AVG(amt)   FROM cust c2   WHERE c2.category = c1.category ); ✔ Here, the inner query depends on the outer query ✔ It runs for each row → making it a correlated subquery 🔹 𝗧𝘆𝗽𝗲𝘀 𝗼𝗳 𝗦𝘂𝗯𝗾𝘂𝗲𝗿𝗶𝗲𝘀 (𝗢𝘃𝗲𝗿𝘃𝗶𝗲𝘄): 📌 𝗕𝗮𝘀𝗲𝗱 𝗼𝗻 𝗥𝗲𝘀𝘂𝗹𝘁 𝗧𝘆𝗽𝗲: Scalar Subquery (single value) Row Subquery Table Subquery 📌 𝗕𝗮𝘀𝗲𝗱 𝗼𝗻 𝗗𝗲𝗽𝗲𝗻𝗱𝗲𝗻𝗰𝘆: Correlated Subquery Non-Correlated Subquery 📌 𝗕𝗮𝘀𝗲𝗱 𝗼𝗻 𝗟𝗼𝗰𝗮𝘁𝗶𝗼𝗻: SELECT clause FROM clause WHERE clause 📌 𝗕𝗮𝘀𝗲𝗱 𝗼𝗻 𝗞𝗲𝘆𝘄𝗼𝗿𝗱𝘀 𝗨𝘀𝗲𝗱: IN EXISTS ANY / ALL 💡 𝗞𝗲𝘆 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆: Subqueries help in breaking complex problems into simpler parts and are widely used in real-world data analysis. 🔥 Day by day, getting closer to mastering SQL! #SQL #LearningJourney #DataAnalytics #Subqueries #Coding #PlacementPreparation #40DaysOfCode

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

To view or add a comment, sign in

Explore content categories