Data Science / Data Analytics / Databases

Advice for Learning SQL Based on Personal Experience

Photo by Glenn Carstens-Peters on Unsplash

If you are trying to break into any type of data profession, SQL is an essential skill to learn.

Hello, my name is Brenden, I’m a data professional based in Dallas and two years ago, I made the decision to break into the incredible world of data. It is one of the best decisions I ever made and I have not looked back since. When I first started this journey two years ago, I was under the impression that I needed to master multiple advanced technical and statistical concepts in order to even have a shot at landing any data role. Being someone who started this journey with very little technical and mathematical education, I did what most people starting their data journeys do, I tried to learn programming from scratch, artificial intelligence, and advanced statistical models, and somehow try to cram it all together in 30 days. Well, after failing to retain all these concepts at once, I realized very quickly that I needed to change my approach. I ended up focusing solely on learning SQL for a couple months before I even thought about tackling something else. I’ve been using SQL for almost two years now, and it’s safe to say I use it more than any other tool or skill on a day-to-day basis.

So why is this story important? Looking back on this experience, I realized I didn’t fully understand what data was and how it behaved. With more and more low-code environments being created and used in the field of data, the importance of understanding data holistically is becoming more important.

“With more and more low-code environments being created and used in the field of data, the importance of understanding data holistically is becoming more important.”

So Why Should I Learn SQL?

There are many different reasons why SQL is useful and plenty of resources on this topic. Once I felt that my SQL skills were solid and moved on to other data concepts, I was able to gain a better understanding of what I was learning because I was able to reference each concept back to SQL in some way. For instance, using the SELECT statement allows you to find the data you are wanting to use whereas the UPDATE statement will permanently change values in your tables. Picking up those small skills like having a further understanding of how your queries impact the database are the skills that will be really useful when working on production solutions. So without further delay, here are some tips that will help you through your SQL/data journey in 2022!

Disclaimer: Learning is a lifelong process. This is not meant to tell you exactly what you need to know, rather, this is to give you some practical advice from my own personal experiences. For further information, please check out Towards Data Science. If you are looking for different ideas on learning SQL this year, keep reading!

1. Learn the Basic Structure of Queries

At a very basic level, many queries follow a similar structure:

Author’s code

This is the basic formula for pulling data in SQL. Yes there are more advanced concepts you can and will use at some point, but this is the skeleton to most queries. When you start learning more advanced concepts, it will be easier to fall back on this skeleton and build off of it as opposed to trying advanced concepts from scratch.

2. Understand the Actions Your Code Has

SQL is an interesting language because each statement has the ability to do so much at once. Let’s take a look at some sample code:

This is how you delete a table in SQL:

Author’s code

This is how you delete a dataframe (or table for our purposes) in Python:

Author’s code

Notice that it takes four lines of code in python to delete data whereas it takes three words to delete data in SQL. This is because SQL interfaces directly with the database, meaning you will often make permanent changes to a database if you are trying to modify tables or the underlying data. Understanding how different statements interact with the database will be helpful when learning to use SQL, as well as making sure you are using the right approach and not deleting or modifying anything you don’t want to, which leads us to our next tip!

3. Understand Different Types of SQL Commands

There are five main types of SQL commands. Think of these five types of commands like groups for SQL statements that are alike. Here is a very brief overview of what the different types do:

  • Data Query Language (DQL), which can be used to find and view data without making any permanent changes to the database.
  • Data Manipulation Language (DML), which is used to make permanent changes to the data, such as updating values or deleting them.
  • Data Definition Language (DDL), which is used to make permanent changes to the table, such as creating or deleting a table.
  • Data Control Language (DCL), which is used for administrative commands, such as adding or removing users of different tables and databases.
  • Transact Control Language (TCL), which is advanced SQL that deals with transaction level statements.

For me personally, understanding these different groups helped me while I was learning SQL as to understand what my code was really doing. This also allowed me to make sure my code was doing exactly what I wanted and that there was no risk of me modifying or deleting historical production data. Feel free to do your own research while learning SQL to add some context to your learning process!

4. Practice With Different Types of Datasets

There will be many times you encounter data that you are not familiar with and will have to rely on your tools and skills, such as SQL, to fit this data for your databases and analyze it accordingly. For instance, I feel like I see a new way a date can be formatted every month. Knowing how datetime functions work in SQL and being able to lean on that will save you time and frustration in the future. When I first started practicing more SQL, I probably would’ve told myself to include more variety in my datasets and have opportunities to learn how to deal with problems I had never worked on before, so when you practice, challenge yourself every now and then to work with data you might not want to work with, because you may find yourself in that situation.

5. Think of SQL In Terms of Trimming Bonsai Trees

Photo by Devin H on Unsplash

With season four of Cobra Kai releasing on Netflix (I would definitely recommend this show if you haven’t seen it yet), I feel like this is a fitting analogy and definitely applicable to learning SQL. In the first Karate Kid movie, they talk about how you need to envision what you want in life and make changes in your life that solidify your vision into a reality, just like trimming a bonsai tree. The catch is that once you make a big change or decision, you normally have to stick with it, just like cutting the limb off of a bonsai tree. Similarly in database work, understanding what your intended final product is before you put a line of code down can be very beneficial, especially in SQL. Are you trying to modify a table in your database? What columns are you trying to delete, create, etc.?

This will help you to design your queries with more intention as well as allowing your code to be more efficient. There are definitely times where you can start coding away without a final product in mind, especially when you are asked to create something from nothing. Both approaches work, but having both approaches in your back pocket will save you time and frustration.

Conclusion

While this is by no means an exhaustive list, I hope that these tips encourage you to start your data journey this year and help you avoid some frustration. SQL isn’t necessarily difficult in terms of its syntax compared to other languages, however, it can be difficult from a systems standpoint just because SQL code by itself doesn’t tell the whole story and you normally need to know what your code does before you press run. Practice your code, understand the basic foundational concepts, and you will be on your way to getting the most from your data.

If you like this article, please let me know! Stay tuned for a possible part 2 as well as other content coming your way in 2022!

Check out some of my other articles!

A New Take on Analytical Workflow Management

Three Analytics Tools and Skills You Can Start Learning Right Now

How to Present: For Aspiring Analysts

Data Visualization Audiences and Scenarios

Three Tech Stacks for Aspiring Analysts

10 Tips for a Successful Internship

What I Learned as a Marketing Analytics Intern

A Day in the Life of a Marketing Analytics Intern

To contact me or receive more content, follow me on Twitter @BMNAnalytics!


5 Tips For Learning SQL in 2022 was originally published in Towards Data Science on Medium, where people are continuing the conversation by highlighting and responding to this story.