I see a lot of SQL posts in my feed, getting the impression that SQL is making a comeback and becoming a hot topic again. Indeed, SQL could be a very handy language for many systems/projects and if you are in Data Science and/or analytic positions knowing SQL not only doesn’t do any harm, but the chances are that you will benefit from it.
However, I have noticed that some of my colleagues who are very good programmers in languages such as Java or Python, struggled to learn SQL and write even a very simple SQL code. They were good programmers, so they definitely did have the skills. What was stopping them from switching to SQL?
I noticed that they all share one thing! SQL is not their first programming language. They are trying to apply the same mentality and thought process as when they were writing Python or Java code to SQL coding.
While all programming languages share some common threads, there are some things that do not apply to all of them. Programming languages such as Python are an imperative language, SQL is essentially a declarative language.
What does imperative or declarative language mean? Very simply put without going into details, it means when you are writing python code, you need to think about all the details of how a task or a computation needs to be done.
But in SQL you need to focus on what needs to be done. More than once, I have seen experienced programmers just starting writing code in SQL already frustrated and asking me: “How do you loop in SQL over rows to compute this or that? SQL is stupid! “. That is imperative language mentality.
While SQL indeed has some looping statements, when writing SQL you need to change your mentality to a declarative language. In fact, one of the reasons that SQL has become such a performant technology for certain tasks is exactly this. You specify to the system what needs to be done, and let the system optimize and decide how it needs to be done.
If you want to learn SQL, start with W3 School SQL Tutorial. It’s free. You can practice online, and within a couple of hours you would learn all you need to learn that you will use most of the time. But, if you are an experienced programmer, don’t forget to first change your thought process.
Unfortunately, SQL was never really standardized. This means that SQL query working on one system, might not work on another. So, the next thing you need to learn is to locate the documentation of SQL for your platform/system and learn how to efficiently search for information in it.
May be use LLM as an assistant but remember that you are in the driver seat. Don’t trust all the things that LLM churns out. Sometimes, their suggestions are terrible; you can write a much better SQL code with just a little bit of thinking.