DEV Community

Cover image for 🚀 How I Learned That Thinking “Small” Can Save Hours of SQL Headaches
Franciele Stefani da Costa
Franciele Stefani da Costa

Posted on

🚀 How I Learned That Thinking “Small” Can Save Hours of SQL Headaches

The day I realized building a query is like playing with Lego

Professors always said: “build and test, build and test.”

And I thought I was already doing that. But honestly, I wasn’t.

My mindset was linear: I wanted to write the entire query at once, hit run, and only then check if it worked.

Guess what? It usually didn’t. 😅

Then one day I watched a video from Ankit Bansal (SQL expert), and that’s when it clicked. 💥

It’s not about going slow—it’s about changing the way of thinking.

👉 Instead of finishing everything and testing later, it’s way better to enjoy the process: build step by step and debug along the way.

And here’s how he did it:

  1. He started with something simple:
WHERE department_id NOT IN (SELECT dep_id FROM dept);
Enter fullscreen mode Exit fullscreen mode
  1. Then, he expanded it with a LEFT JOIN:
LEFT JOIN dept
ON emp.department_id = dept.dep_id;
Enter fullscreen mode Exit fullscreen mode
  1. Next, he pulled in the full data:
SELECT emp.*, dept.dep_name FROM emp;
Enter fullscreen mode Exit fullscreen mode
  1. Finally, he filtered just what he needed:
WHERE dept.dep_name IS NULL;
Enter fullscreen mode Exit fullscreen mode

So instead of trying to write everything in one go, he validated each block until the solution was crystal clear.


💡 What I Learned

This style has a fancy name: incremental thinking.

But for me, it simply means: “don’t lose your mind.”

  • Fewer mistakes: you test each piece before moving on.
  • Easier debugging: when something breaks, you know exactly where.
  • Lighter brain load: it’s easier to reason in smaller chunks.
  • Real learning: you understand the journey, not just the final query.

And since my dream is to become a Data Engineer, I can see how this mindset will be essential.

Data engineering is all about dealing with complex systems, huge datasets, and tricky transformations — and there’s no way to survive without building things step by step.


🎯 How to Train This Mindset

If you also tend to write giant queries all at once, here’s a better way to practice:

-- Step 1: look at all the data
SELECT * FROM table;

-- Step 2: add filters
SELECT * FROM table WHERE condition;

-- Step 3: join tables
SELECT * FROM table1
LEFT JOIN table2 ON condition;

-- Step 4: refine with window functions, groupings, etc.
Enter fullscreen mode Exit fullscreen mode

The idea is: build and test each step.

Don’t try to be “Neo from the Matrix” writing a massive query and only checking if it works at the end.


🎤 Conclusion

I used to think “build and test” meant slowing down.

But now I see it’s the opposite: it’s actually faster, because you make fewer mistakes.

Now, whenever I write a query, I remind myself:

“Take it easy, Fran. Build the Lego one piece at a time.” 🧩

And who knows — one day, as a Data Engineer, I’ll look back and thank myself for training this mindset early on.

How about you? Do you still try to write it all at once, or have you embraced the incremental path? I’d love to hear your experience! 😅


✍️ If you enjoyed this post, drop a comment, share it, and follow me here — I’m sharing my journey as a junior dev on the path to becoming a Data Engineer. 🚀

Top comments (0)