Introduction to SQL Toolbox
Explore how to improve your SQL writing skills using practical examples in PostgreSQL. Learn to express problems clearly, work interactively on queries, and gain confidence in both basic and advanced SQL techniques to write efficient, reliable database applications.
We'll cover the following...
In this part, we’re going to add to our proficiency in writing SQL queries. The structured query language doesn’t look like any other imperative, functional, or even object-oriented programming language.
SQL techniques
This part contains a long list of SQL techniques from the most basic select clause to advanced lateral joins, each time with practical examples working with a free database that you can install at home.
It’s highly recommended that you work with the queries yourself. A key aspect of this part is that SQL queries aren’t typically written in a text editor; instead, they’re interactively tried out in pieces and stitched together once the spelling is spot-on.
SQL writing process
The SQL writing process is mainly about discovery. Unlike most programming languages where we have to focus on a solution we think will solve our problem, SQL requires us to explain our problem. That’s quite different and requires looking at your problem in another way and understanding it well enough to be able to express it in detail in a single sentence.
Here’s some good advice, when you’re struggling to write a SQL query, first write down a single sentence in your native language that perfectly describes what you’re trying to achieve. When you do that, writing SQL is going to be easier.
Effective technique
An effective technique in writing such a sentence is talking out loud because writing and speaking come from different parts of the brain. It’s the same as debugging a complex program and it helps a lot to talk about it with a colleague.
Writing applications
After dealing with the basic fundamentals of the language, this part spends time on more advanced SQL concepts and PostgreSQL, along with how you can benefit from them when writing your applications, making you a more effective developer.
This section reviews important and basic parts of an SQL query. The goal for us is to be comfortable enough with writing SQL that we don’t feel like we’ve lost control over the details of its execution plan; instead, we can rely on our RDBMS of choice for that. Of course, it’s much easier to reach that level of trust when we use PostgreSQL because it’s fully open source, well documented, supports a very detailed explain command, and its code is very well commented, making it easy enough to read and review.