Apr 3, 2023

Complete Guide to learn SQL in 2023

Are you interested in learning how to use SQL but don't know where to start? Don't worry, you're not alone.

SQL, or Structured Query Language, is a programming language that is used to manage and manipulate data in relational databases. While SQL can seem intimidating to non-technical people, the road to learning SQL can be broken down into manageable steps.

How to learn SQL? What are some good online resources, like websites, blogs, or videos?

In this blog post, we'll guide you through the process of learning SQL in a way that is welcoming and approachable for people who have no coding background.

Step 1: Understand the Basics

Before diving into SQL, it's important to understand some basic concepts.

First, what is a database?

A database is a collection of data that is organized in a specific way to allow for efficient storage, retrieval, and management of data. A relational database is a type of database that organizes data into tables, with each table representing a different type of information.

Second, what is SQL used for?

SQL is used to query, or ask questions of, a database. It allows users to retrieve, update, and manipulate data stored in a relational database.

Step 2: Get Familiar with SQL Syntax

SQL syntax may seem overwhelming at first, but it's actually quite straightforward once you understand the basics. SQL statements are made up of keywords, commands, and clauses that are used to tell the database what to do. Here are some of the most commonly used SQL commands:

SELECT : retrieves data from one or more tables

FROM : specifies the table or tables to retrieve data from

WHERE : filters data based on a specified condition

ORDER BY : sorts data in ascending or descending order based on a specified column

JOIN : combines data from two or more tables based on a specified column

Basic SQL queries along with their syntax:

1. Select all rows from a table

The first query is a simple way to retrieve all the information from a database table.

Syntax:

SELECT * FROM table_name;

This SELECT statement uses the * symbol to represent “all the columns”. After that, the FROM clause indicates the table to be read.

Example:

SELECT * FROM customers;

This will return all rows and columns from the "customers" table.

2. Select specific columns from a table

You can also only show a few columns from a table.

Syntax:

SELECT column1, column2, column3,... FROM table_name;

Let’s suppose we want a E-mail list with the columns " first_name ", " last_name ", and " email ". The query is very simple:

Example:

SELECT first_name, last_name, email FROM customers;

We specified the columns we want to extract from the table: " first_name ", " last_name ", and " email ".. In the second line of the query, we use the FROM clause to indicate the table to read.

3. Filter rows based on a condition

Usually you don’t want to see all the data in a database. You want to see only the rows that match certain criteria: products from one product family. In SQL, this is called filtering the data. The WHERE clause filters the data you want from the rest of the data in the table. It extracts records that match certain conditions.

Syntax:

SELECT * FROM table_name WHERE condition;

For example, suppose we want a list of " customers " who lives in " New York City "

Example:

SELECT * FROM customers WHERE city = 'New York';

This will return all rows from the "customers" table where the "city" column is equal to "New York". The WHERE clause indicates that we only want to obtain those city = 'New York' is TRUE . Other records will not be part of the result. In other words, we are filtering records from the table customers.

4. Sort rows in Ascending or Descending order

Often you want to see query results in a certain order, such as products from the cheapest to the most expensive or product names in alphabetical order. The clause ORDER BY is used to define how the records will be ordered in the query result.

Syntax:

SELECT * FROM table_name ORDER BY column_name [ASC|DESC];

Example:

SELECT * FROM customers ORDER BY last_name ASC;

This will return all rows from the "customers" table sorted in ascending order by the "last_name" column. (ASC - Ascending and DESC - Descending).

5. Join Multiple Tables

You can join tables using JOIN, including INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, and CROSS JOIN .

Syntax:

SELECT * FROM table1 JOIN table2 ON table1.column_name = table2.column_name;

In this example, we want to join data from the tables customer and city. INNER JOIN needs to come after FROM and the name of the first table, customer. After INNER JOIN, place the name of the second table, city. The records with data from both tables are matched by ON with the condition to join. The records in the table city are matched to the records from the table customer if they have the same value in the column id in the table customer and in the column customer_id in the table city.

Example:

SELECT customers.first_name, orders.order_date FROM customers JOIN orders ON customers.customer_id = orders.customer_id;

Step 3: Practice with Sample Databases

One of the best ways to learn SQL is to practice using a sample database. Many online resources offer free sample databases that you can use to practice your SQL skills. Some popular sample databases include:

Northwind: a sample database that includes information about a fictional company's products, orders, and customers.

Download here.

Chinook: a sample database that includes information about a fictional music store's inventory, customers, and sales.

Download here.

Sakila: a sample database that includes information about a fictional DVD rental store's inventory, customers, and rentals.

Download here.

Using a sample database will allow you to practice writing SQL queries without having to worry about creating your own data.

Step 4: Learn How to Optimize Your Queries

Once you have a good understanding of SQL syntax and have practiced with a sample database, you can start to optimize your queries. Optimization refers to the process of making your SQL queries more efficient, which can help improve the performance of your database.

Some tips for optimizing your SQL queries include:

Avoid using SELECT * (which retrieves all columns from a table) and instead specify only the columns you need.

Use indexes to speed up queries that involve large amounts of data.

Avoid using subqueries (queries within queries) unless necessary, as they can be slow and resource-intensive.

Step 5: Keep Learning

SQL is a powerful tool for managing and manipulating data, and there is always more to learn. As you become more comfortable with SQL, consider learning more advanced topics such as:

Stored procedures: pre-written SQL code that can be reused in multiple queries

Triggers: code that is automatically executed when a certain event occurs, such as when data is inserted or updated in a table

Views: virtual tables that are created based on the results of a query, allowing for easier data analysis and reporting.

Free Resources to Build a Strong Foundation in SQL

4 Free Websites to learn SQL

1.  Introduction to SQL by Coursera

Time to Complete- 15 hours to complete

Best For- Intermediate Level

Introduction to Structured Query Language (SQL) by the University of Michigan will start you off learning SQL through the MySQL flavor. You’ll learn how to create and design databases with MAMP or XAMPP, and learn the basic syntax of the MySQL language.

2. Excel to Mysql by Coursera

Time to Complete- 7 months to complete

Best For- Beginners

In this Specialization, you’ll learn to frame business challenges as data questions. You’ll use powerful tools and methods such as Excel, Tableau, and MySQL to analyze data, create forecasts and models, design visualizations, and communicate your insights. In the final Capstone Project, you’ll apply your skills to explore and justify improvements to a real-world business process.

3. Sql for Data Analysis by Udacity

Time to Complete- 4 Weeks

Best For- Beginners

This course is completely free and covers SQL to extract and analyze data stored in databases. SQL is used to perform data analysis in this course. First, you will learn SQL basics like how to extract data, SQL joins to join tables and SQL aggregations.

Then you will learn how to perform complex analysis and manipulations using subqueries, temp tables, and window functions.

4. Sql for Data Science by Coursera

Time to Complete- 14 hours

Best For- Beginners

In this course, you will understand the fundamentals of SQL and work with data so that you can begin analyzing it for data science purposes.

At the beginning of the course, you will learn the SQL basics and assume you do not have any knowledge or skills in SQL. After that, you will write both simple and complex queries to help you select data from tables and start to work with different types of data like strings and numbers.

This course will also teach you how to create a table and how to move data into them. At the end of this course, you will learn common operators and use case statements and concepts like data governance and profiling.

6 YouTube Channels to learn SQL

1. freeCodeCamp.org

7.5M subscribers

2. Programming with Mosh

3.21M subscribers

3. Joey Blue

64.3K subscribers

4. Edureka!

3.74M subscribers

5. Web Dev Simplified

1.25M subscribers

6. Adam Finer - Learn BI Online

59.9K subscribers

 

Free Books to learn SQL

1. SQL Cookbook

Author Name: Anthony Molinaro

Publisher: O′Reilly

Latest Edition: 1st edition

No of Pages: 504 pages

SQL Cookbook is a book written by Anthony Molinaro. In this book, the author shares his favorite SQL techniques and features. The book includes topics like Window functions, Pivoting rows into columns, reverse-pivoting columns into rows. In this book, you will also learn how to create histograms, generate running-totals and subtotals, etc.

Download here : Free book link

2. SQL Practice Problems

Author Name: Sylvia Moestl Vasilik

Publisher: Independently Published

Latest Edition: 1st edition

No of Pages: 127 pages

SQL Practice problems is useful SQL book. It provides practice problems, which gives you an advanced level of SQL experience by solving sets of targeted problems. These aren’t just into problems designed as syntax examples. The book covers the most common problems you encounter when you deal with data.

Download here : Free book link

3. Learning SQL

Author Name: Alan Beaulieu

Publisher: O′Reilly

Latest Edition: 2nd edition

No of Pages: 352 pages

Learning SQL is a book written by Alan Beaulieu. Each chapter of this book teaches you a key SQL concept or technique, with various illustrations and annotated examples. Exercises at the end of each chapter allow you to practice the skills you learn.

In this book, you will learn several advanced features like manipulating and retrieve data, create database objects, like tables, indexes. By learning this book, you’ll also be able to learn how to use the power and flexibility of this SQL.

Download here : Free book link

4. Oracle PL/SQL Programming

Author Name: Steven Feuerstein

Publisher: O′Reilly

Latest Edition: 6th edition

No of Pages: 1392 pages

Oracle PL/SQL programming, written by Steven Feuerstein. This definitive guide is what you need to make the most of Oracle’s. This SQL book describes the features and capabilities of PL/SQL up through Oracle Database 12c.

With a wide range of and a lively sense of humor, this SQL learning book explains language fundamentals. It also explains advanced coding techniques and best practices.

Download here : Free book link

5. SQL pocket guide

Author Name: Jonathan Gennick

Publisher: O′Reilly

Latest Edition: 3rd edition

No of Pages: 208 pages

SQL Pocket Guide was written by Jonathan Gennick. The book also teaches how the systems use SQL functions, regular expression syntax, and type conversion functions. All examples given SQL statements in this book execute against a set of tables, with data that you can quickly download.

The book covers topics like Oracle’s support of the recursive with syntax and the addition of PIVOT and UNPIVOT operators. The book also covers how you can PostgreSQL’s support of recursive with window functions, DB2 syntax, and datatypes, etc.

Download here : Free book link

 

Free websites to practice SQL

1.      SQL quiz by w3schools

2.      Datalemur by Nick Singh here

Conclusion

Learning SQL may seem daunting at first, but by breaking it down into manageable steps and practicing with sample databases, you can quickly become proficient in querying and manipulating.

We at Alphaa AI are on a mission to tell #1billion #datastories with their unique perspective. We are the community that is creating Citizen Data Scientists, who bring in data first approach to their work, core specialisation, and the organisation.With Saurabh Moody and Preksha Kaparwan you can start your journey as a citizen data scientist.

Need Data Career Counseling. Request Here
More from Citizen Data Scientist

Ready to dive into data Science? We can guide you...

Join our Counseling Sessions

Find us on Social for
data nuggets❤️