How to learn SQL

Technology
By -


How to learn SQL



One of the most crucial things we can do for people learning SQL is to provide them with a clear road map that will enable them to handle key subjects in the proper order.

This post will provide you with a solid learning strategy for SQL if you're a beginner and want to start honing your skills.

Step 1. Understand what SQL is and how we use it

The most popular language for extracting and organizing data from relational databases is SQL. A table with rows and columns is what a database is. The language of databases is SQL. It makes it easier to get precise data from databases that are then used for analysis. To extract the data you require from a company's database, SQL would be required, even if the research was performed on a different platform, such as Python or R.

SQL manages a large amount of data, especially if there is a lot of data that is being written simultaneously and there are too many data transactions.

Although there are other SQL versions and frameworks, MySQL is the most used. An open-source alternative to SQL, MySQL facilitates the management of back-end data for web applications. SQL is used by many businesses, including Facebook, Instagram, WhatsApp, and others, for back-end data processing and storage. A query optimizer processes a SQL query as it is written, executed, or interpreted. As the query reaches the SQL server, it goes through three phases of compilation: parsing, binding, and optimization.

  • Parsing – A process to check the syntax
  • Binding – A process to check the query semantics
  • Optimization – A process to generate the query execution plan

In the third stage, all conceivable permutations and combinations are created in an effort to quickly identify the most efficient query execution plan. The query will perform better the faster it runs.

Step 2. Download some free SQL tools

You can skip this step if you already have a SQL tool installed on your computer. If it's not MySQL, that's fine (what we use at Maven). The SQL versions are all very similar to one another. Here, there is no wrong decision. It's important to just start moving.

These MySQL utilities are robust, cost-free, and simple to install if you're just getting started. Also, many businesses utilize MySQL on the job. At Maven, we use them to teach our SQL classes.



Step 3. Get access to a database to start practicing

Getting access to your company's database is the best course of action here. If that's a possibility, I would strongly advise you to take that action before beginning to use SQL to extract some data relevant to your role. Practice with real-world situations that make sense to you in the context of your business is the greatest approach to learning. You will need to obtain access to a live database somewhere else if your employer won't allow you to access a database to pull data that is pertinent to your position.

Here are a couple of solid options for practice databases:

  • MySQL Data Analysis course Take this course if you currently have an unlimited access membership to Maven Analytics. Since it was designed for beginners, we start at the very beginning. Also, it includes a fantastic database for practice.
  • You can download example databases from MySQL if you are not a member of Maven Analytics and feel comfortable trying certain things out on your own.
  • Sakila sample database
  • Employees sample database

Step 4. Get your hands dirty, starting with the Big 6 of SQL querying

Now, this is where the magic starts to happen. You're about to start writing SQL queries!

It's at this stage you'll start to see that SQL really isn't that bad. It's an intuitive language that anyone can learn. And it can be pretty fun when you realize how easy it is to start pulling information out of a database.

Note: This is the point in my roadmap where I occasionally get roasted by "academics." I'm crazy to just throw you into query writing, they say as they fly in. It is recommended that foundational theory be taught first, followed by an explanation of relational databases, how tables link to one another, appropriate data model structure, etc. This was also the topic of a rather entertaining TikTok debate between an academic and someone who lives in the real world, like me, with 50+ comments on one of my videos. It was quite entertaining, but I'm unable to locate the link. My goal is to get you to the moment where you realize you can do this, and that it can be fun, quick, and in the simplest possible way.

Then, a lightbulb went off. The momentum begins to increase. You can see the benefits of SQL. You're enjoying yourself. You are yearning for more. Then we continue to advance, and sure, eventually, we do want to discuss relational database theory and best practices for data models. To increase the likelihood of success, we just want to do that at the best time for our students.

You might feel bored or overwhelmed before you ever find love if I went the academic approach and buried you in theory and difficult technical concepts (that, to be honest, you might not really require on the job).

So, I always get you writing queries on day 1

Your first stop is to focus on the Big 6 of SQL Querying.

SELECT

FROM

WHERE

GROUP BY

HAVING

ORDER BY

These six statements and clauses will be used to retrieve data from certain database tables (joining multiple tables will come later). This is where you'll see that using a SELECT and a FROM in your code is just as simple as SELECTING data FROM a particular table—pretty logical, huh?

If you have unlimited access to Maven Analytics, you already have access to our MySQL Data Analysis course. Your first trip there will be the Big 6. I suggest using the excellent dev.mysql.com documentation if you want to go it alone. Simply Google "dev. MySQL" and the topic you want to read about, for instance, dev.mysql.com. You can access this top result by using SELECT:

dev.mysql.com SELECT statement

Repeat this and practice with your sample database until you feel confident you understand the Big 6 and when and how to use them.

These 6 concepts will be your SQL foundation.

Step 5. Learn aggregate functions, and use them with GROUP BY to slice and dice your data

The idea of generating groups and summarising those groupings with key metrics will be familiar to you if you are familiar with Excel's pivot tables. You can slice and dice your data into groups using GROUP BY, and this is exactly what you'll be doing using aggregate functions in SQL. 

Here are the aggregate functions you should learn to use.

COUNT( )

SUM( )

AVG( )

MIN( )

MAX( )

Again, we'll cover these in our MySQL Data Analysis course, or you can turn to Google and read up. Just search 'dev.mysql.com COUNT', etc.

Step 6. Learn some relational database theory - database design, table relationships, data types, etc.

Here are the concepts you'll want to focus on here:

  1. Primary and Foreign Key Mapping

  2. Cardinality

  3. Normalization

  4. Data Types

The idea of producing groups and summing those groupings with key metrics will be familiar to you if you are familiar with Excel's pivot tables. You can slice and dice your data into groups using GROUP BY, and this is exactly what you'll be doing with aggregate functions in SQL.

MySQL Data Types

Step 7. Practice querying data from multiple tables

Here are the concepts I would recommend focusing on:

INNER JOIN

LEFT JOIN

UNION

And to be thorough, you should be aware of a few additional join types. However, for 95% of your needs, you'll use the three mentioned above. RIGHT JOINS have never been used in code at work, while CROSS JOINS and FULL OUTER JOINS are used far less commonly.

Again, if you're an Unlimited Access Maven Analytics customer, you've had access to these topics previously in our MySQL Data Analysis course. If you wish to learn these concepts on your own, look up terms like "dev.mysql.com INNER JOIN" on Google and begin practicing using a practice database of your own.

Step 8. Learn how to create your own schemas and tables

Although DBAs and Data Engineers normally do these activities, being able to do them yourself can actually help you become a stronger and more adaptable Analyst. They also unquestionably aid in your ability to comprehend databases on a deeper level. Here are the first concepts I would recommend you cover:

CREATE SCHEMA

CREATE TABLE

ALTER TABLE

DROP TABLE

INSERT

UPDATE

DELETE

If you're a Maven Analytics member, you'll get access to our MySQL Data Analysis course, which covers this final set of ideas. Again, a Google search for "dev.mysql.com CREATE SCHEMA" or similar terms will lead you to some excellent material.

Step 9. Set reasonable expectations

This road map is intended to assist you in laying a solid SQL foundation. Is this all there is to know about SQL? Sure, there is a lot more you can learn, but it's a really good place to start and offers you a flow where you can learn things in a logical manner that will make sense to you and help you start generating some momentum.

Aim to get a head start here before going on to more complicated ideas like CTEs/temp tables/subqueries, window functions, automation with triggers and scheduled events, etc. Learning SQL is a lifelong endeavor. I sincerely hope you find this article to be useful and that you will put it to use to advance in your job and pick up a useful skill.

Tags:

Head