Skip to main content

Featured Post

AI-Native SDLC for Web Development: A Step-by-Step Guide with Claude Code

In my previous post I summarized Anthropic's AI-Native SDLC Playbook , which explains how to redesign the software lifecycle once AI agents can write code faster than your process can absorb it. This post is the practical follow-up: how to actually apply it to a web development project, step by step , with files you can copy into your own repo. Throughout this post I'll use one running example: a Next.js + TypeScript e-commerce app that needs a new "Wishlist" feature. The same steps work for React + Node, Vue, Laravel, Django, or any other web stack. Only the commands change. The workflow at a glance Each stage ends by committing a file, and the next stage starts by reading it: Plan → docs/intent/wishlist.md (what and why) Design → docs/specs/wishlist.md (how) Build → code + tests (guided by CLAUDE.md and Skills) Test → passing tests + CI evals Deploy → PR with AI review findings → human approval → CI/CD Maintain...

Understanding SQL Query Execution Order

When writing SQL queries, understanding the execution order is crucial for writing efficient and optimized code. Many beginners assume that queries execute in the order they are written, but in reality, SQL follows a specific sequence of execution.

SQL Execution Order

SQL queries run in the following order:

1️⃣ FROM + JOIN
2️⃣ WHERE
3️⃣ GROUP BY
4️⃣ HAVING
5️⃣ SELECT (including window functions)
6️⃣ ORDER BY
7️⃣ LIMIT

Let’s break down each step with examples.


1. FROM + JOIN (Data Retrieval)

The SQL engine first retrieves data from the specified table(s) and applies any JOIN operations.

🔹 Example:


SELECT employees.name, departments.department_name FROM employees JOIN departments ON employees.department_id = departments.id;

Here, the JOIN happens before any filtering (WHERE) or grouping (GROUP BY).


2. WHERE (Filtering Data)

Once data is retrieved, the WHERE clause filters rows before aggregation occurs.

🔹 Example:


SELECT * FROM employees WHERE salary > 50000;

This removes rows where the salary is less than or equal to 50,000 before moving to the next step.


3. GROUP BY (Grouping Data)

If aggregation is needed, SQL groups data at this stage based on specified columns.

🔹 Example:


SELECT department_id, COUNT(*) as employee_count FROM employees GROUP BY department_id;

Here, the query groups employees by department_id and counts them.


4. HAVING (Filtering Groups)

The HAVING clause filters grouped data (unlike WHERE, which filters individual rows).

🔹 Example:


SELECT department_id, COUNT(*) as employee_count FROM employees GROUP BY department_id HAVING COUNT(*) > 5;

Only departments with more than five employees are included in the results.


5. SELECT (Choosing Columns & Applying Window Functions)

Now, the SELECT statement retrieves specific columns and applies functions like window functions.

🔹 Example (with a window function):


SELECT name, salary, RANK() OVER (ORDER BY salary DESC) AS salary_rank FROM employees;

The RANK() function assigns ranks based on salary after filtering and grouping are completed.


6. ORDER BY (Sorting the Results)

The ORDER BY clause sorts the final output.

🔹 Example:


SELECT name, salary FROM employees ORDER BY salary DESC;

Results are displayed in descending order of salary.


7. LIMIT (Restricting Rows)

Finally, the LIMIT clause restricts the number of rows in the output.

🔹 Example:


SELECT name, salary FROM employees ORDER BY salary DESC LIMIT 5;

Only the top five highest-paid employees are returned.


Why Understanding SQL Execution Order Matters

✅ Helps in debugging complex queries
✅ Optimizes performance by reducing unnecessary computations
✅ Ensures correct use of filters and aggregations

Understanding how SQL processes queries behind the scenes allows you to write better, more efficient database queries. Master this execution order, and you'll become a more effective SQL developer! 🚀

Comments

Popular posts from this blog

Top 5 React.js Performance Optimization Techniques for 2025

React.js continues to dominate the front-end development landscape due to its flexibility, component-based architecture, and performance. However, as applications grow, performance issues can emerge, affecting user experience. Here are the top five performance optimization techniques every React developer should consider in 2024. 1. Use React.memo for Component Memoization React.memo is a higher-order component that prevents unnecessary re-renders by memoizing the result. It only re-renders when props change, improving performance for functional components that rely on the same data. import React from 'react';  const ExpensiveComponent = React.memo(({ data }) => {      console.log('Rendering ExpensiveComponent');      return <div>{data}</div>;  }); export default ExpensiveComponent; 2. Implement Code Splitting with React.lazy and Suspense Code splitting reduces the initial load time by splitting the code into smaller bundles. Re...

Best Practices for Securing Personal and Business Data in 2025

In today’s digital landscape, cybersecurity is more critical than ever. With increasing cyber threats, data breaches, and privacy concerns, individuals and businesses must take proactive steps to secure their data. This guide outlines the most effective security practices for 2025. 1. Implement Strong Authentication Measures Passwords alone are no longer sufficient to protect sensitive accounts. Instead, consider: ✅ Multi-Factor Authentication (MFA): Require users to verify their identity using an additional factor, such as an SMS code, authenticator app, or biometric authentication. ✅ Passkeys & Password Managers: Use passkeys where available and store strong, unique passwords in a secure password manager. 2. Encrypt Sensitive Data Encryption ensures that even if data is stolen, it remains unreadable without the decryption key. 🔹 Use end-to-end encryption (E2EE) for messages and emails. 🔹 Encrypt stored data on cloud services, external drives, and local machines. 🔹 Consider ...