𝗙𝗜𝗟𝗧𝗘𝗥 𝗰𝗹𝗮𝘂𝘀𝗲 — 𝗰𝗹𝗲𝗮𝗻𝗲𝗿 𝗰𝗼𝗻𝗱𝗶𝘁𝗶𝗼𝗻𝗮𝗹 𝗮𝗴𝗴𝗿𝗲𝗴𝗮𝘁𝗶𝗼𝗻 CASE WHEN inside aggregations is everywhere. But there's a cleaner way in modern SQL. The 𝗙𝗜𝗟𝗧𝗘𝗥 clause. Old way: SELECT SUM(CASE WHEN status = 'paid' THEN amount END) AS paid, SUM(CASE WHEN status = 'pending' THEN amount END) AS pending FROM orders; New way with FILTER: SELECT SUM(amount) FILTER (WHERE status = 'paid') AS paid, SUM(amount) FILTER (WHERE status = 'pending') AS pending FROM orders; Same result. Much cleaner. Works with COUNT, AVG, MIN, MAX — any aggregate function. The best SQL isn't always the most complex — sometimes it's just more readable. Have you used FILTER before? #SQL #DataAnalysis #PostgreSQL #DataEngineering #Analytics
Roshleen Singla’s Post
More Relevant Posts
-
Why NOT EXISTS is faster than LEFT JOIN (in many cases) Both queries solve the same problem: Find records that don’t have a match But internally, they behave very differently. LEFT JOIN: • Joins entire tables • Creates intermediate result • Then filters NULLs NOT EXISTS: • Checks row by row • Stops at first match • Avoids unnecessary scans LEFT JOIN = “process everything, then filter” NOT EXISTS = “check and skip early” That’s why NOT EXISTS often performs better on large datasets. But remember: Modern SQL optimizers can rewrite both — always check execution plans. Small query change. Big performance difference. #SQL #SQLTips #AdvancedSQL #QueryOptimization #Database #DataEngineering #Analytics #SQLServer #PostgreSQL #CodingTips
To view or add a comment, sign in
-
-
You write SQL from top to bottom. Your database reads it in a completely different order. 🧠🔍 Ever wondered why you can't use an alias you created in a SELECT statement inside your WHERE clause? Or why HAVING feels like a second WHERE? It’s because of the Logical Order of Execution. If you want to debug like a pro and stop guessing why your queries are failing, you need to memorize this "Cheat Code." 📜 The SQL Execution Cheat Sheet: Think of your query like a filter. It doesn't start at the top; it starts with the Source. FROM / JOIN: "Where is the data coming from?" (The database grabs the tables first). WHERE: "Which rows do I need?" (It filters the raw data). GROUP BY: "How should I bucket them?" (It organizes rows into groups). HAVING: "Which groups do I keep?" (It filters the groups, NOT the rows). SELECT: "What columns do I show?" (Finally! This is where aliases are born). DISTINCT: "Any duplicates?" (It cleans the final view). ORDER BY: "How should it look?" (The very last thing—sorting). TOP / LIMIT: "How many should I send back?" #SQL #DataEngineering #CodingTips #MsSQL #Database #CareerAdvice #TechHacks #SanthoshS
To view or add a comment, sign in
-
-
SQL fundamentals feel complex… until you see the system behind it. Think like this: • Server → Database → Schema → Table → Like a city → building → floor → room • Row → One person’s record • Column → One type of detail (name, salary) • Primary Key → Aadhaar/unique ID Now SQL logic: • SELECT → What do you want? • FROM → Where from? • WHERE → Which ones? • GROUP BY → Combine similar • HAVING → Filter groups • ORDER BY → Sort results Real twist most beginners miss: You write SQL top → down But database runs it inside → out Lesson: SQL is not syntax. It’s structured thinking + logical flow. Once you understand the system → everything else becomes easy #SQL #DataEngineering #DataAnalytics #LearnSQL #CodingTips #TechLearning #Database #DataScience #DevCommunity
To view or add a comment, sign in
-
SQL Cheat Sheet👇 SQL isn’t just about writing queries it’s about understanding how they execute. Every query follows a flow: FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT This means data is first picked, then filtered, grouped, and only at the end selected and sorted. Once you understand this sequence along with basics like JOINs and aggregations, your queries become more accurate and efficient. #SQL #DataAnalytics #DataEngineering #Learning #TechSkills
To view or add a comment, sign in
-
-
🚀 Day 28 of SQL Journey – Subqueries (Part 3) Today, I explored an important classification of subqueries based on dependency: Correlated and Non-Correlated Subqueries 🔍 🔹 Correlated Subqueries These subqueries depend on the outer query and execute once for every row processed. While powerful for row-wise comparisons, they can be slower due to repeated execution. 🔹 Non-Correlated Subqueries These are independent of the outer query and execute only once. They are more efficient and ideal when a single aggregated result is sufficient. 📊 The key difference lies in execution behavior and performance impact. Choosing the right type of subquery can significantly optimize your queries. 💡 Key Insight: Use correlated subqueries for dynamic, row-level comparisons, and non-correlated subqueries for static, overall comparisons. #SQL #Learning #DataAnalytics #Database #SQLJourney #40DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 36/100 — SQL Indexes: Speeding Up Queries ⚡📊 Today I learned how to improve query performance using Indexes in SQL — a key concept in real-world systems. 📊 What is an Index? 👉 A data structure that improves the speed of data retrieval 👉 Works like an index in a book — helps you find data faster 📌 What I explored today: 🔹 Creating indexes 🔹 How indexes improve performance 🔹 When to use (and avoid) indexes 🔹 Impact on large datasets 💻 Example: CREATE INDEX idx_customer_id ON orders(customer_id); 📊 Without Index: ❌ Full table scan (slow) 📊 With Index: ✅ Faster data retrieval 🔥 Key Learnings: 💡 Indexes significantly improve query performance 💡 Very useful for large datasets 💡 Overusing indexes can slow down inserts/updates 🚀 Real-world use cases: ✔ High-performance applications ✔ Large databases (millions of rows) ✔ Frequently searched columns 🔥 Pro Tip: 👉 Use indexes on: Columns used in WHERE Columns used in JOIN Columns used in ORDER BY 📊 Tools Used: SQL | MySQL ✅ Day 36 complete. 👉 Quick question: Do you focus more on writing queries or optimizing performance? 🤔 #Day36 #100DaysOfData #SQL #Indexes #PerformanceOptimization #DataAnalytics #LearningInPublic #CareerGrowth #JobReady #InterviewPrep
To view or add a comment, sign in
-
-
Most people learn SQL. Few master it. Here's the full SQL Master Tree , 18 areas, basics to advanced: 🔷 Database Fundamentals 🔷 Data Types, DDL, DML, DQL 🔷 JOINs, Subqueries, Views 🔷 Indexing, Transactions, ACID 🔷 Normalization, Window Functions, CTEs 🔷 Performance Optimization & Real-World Usage If I had to pick 3 concepts that make the biggest difference in day-to-day data work: 1. Window Functions (ROW_NUMBER, RANK, PARTITION BY) 2. CTEs — readable, reusable logic 3. Indexing + partitioning — because slow queries are career-limiting 😅 Save this. Share it with someone learning SQL. What would you add to this tree? 👇 #SQL #DataEngineering #Analytics #DataScience #LearningInPublic
To view or add a comment, sign in
-
-
SQL Progress: Aggregations & Joins! What I learned and practiced today: 1. Aggregate Functions: It’s becoming easier to decide when to use GROUP BY and how to handle multiple aggregations in one query. 2. Data Precision: Handling decimal calculations and rounding is becoming second nature now. It’s all about making the final output clean and professional. I love to learn from you! If you have any tips or a better way to solve these, please type them in the comments! قليل مستمر خير من كثير منقطع #SQL #DataEngineering #PostgreSQL #LeetCode #100DaysOfCode #LearningInPublic #ProblemSolving #DataAnalytics
To view or add a comment, sign in
-
-
As I continue my SQL learning journey, I moved beyond just creating tables to understanding how to modify and manage them effectively. This is done using DDL (Data Definition Language) commands. At first, it feels like just structural changes, but these commands play a huge role in maintaining and evolving a database. Here’s what I explored: • Using ALTER to add, modify, or delete columns • Using DROP to completely remove tables or databases • Using TRUNCATE to quickly delete all records while keeping the structure • Using RENAME to update table or column names And the most important part: If you execute a DDL command → It is auto-committed There’s no rollback → Changes are permanent Structure + Changes = A well-maintained database. Small step, but a very important one in understanding how databases evolve in real-world scenarios. Read here →https://lnkd.in/dkG_UWnG #DataAnalytics #SQL #DatabaseManagement
To view or add a comment, sign in
-
🚀 Day 26 – SQL Learning Journey Today’s focus was on one of the most powerful concepts in SQL: Subqueries & Correlated Subqueries 🔍 🔹 Subqueries (Inner Queries) - A query written inside another query - Used to break complex problems into simpler steps - Can be used in "SELECT", "WHERE", or "FROM" clauses - Example use: finding customers with above-average spending 🔹 Correlated Subqueries - A subquery that depends on the outer query - Executes row-by-row, making it more dynamic - Useful for comparisons within groups (like per customer, per store, etc.) 💡 Key Learnings: ✔ Simplified complex filtering logic ✔ Learned when to use subqueries vs joins ✔ Understood performance impact of correlated queries ✔ Practiced real-world scenarios like ranking, filtering, and segmentation 📊 Realizations: Subqueries are great for clarity, but correlated subqueries require careful use due to performance considerations. Consistency is the key 🔥 — one step closer to mastering SQL! #SQL #DataAnalytics #LearningJourney #Subqueries #CorrelatedSubqueries #Day26 generate a image and take a example of dataset
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development