SQL Queries
8
Lessons
2
Videos
All
Skill Level
4 Hours
Duration
English
Language
Set Up & Introduction
In order to get started, make sure you have your environment set up. To do this, I recommend referencing these links:
- You can download MySQL here.
- One free interface I find very useful in writing SQL commands is PopSQL. Which you can download here.
Before we dive into writing SQL queries, it’s important to understand what SQL and MySQL are. SQL (Structured Query Language) represents the syntax used in manipulating relational databases, whereas MySQL is a RDBMS (Relational Database Management System). In other words, MySQL uses Structured Query Language to manipulate databases.
Shown below are two tables within a database. The table on the left shows the players trying out for sports teams while the table on the right shows the coaches for each sport.
Completing this course will help you:
- Understand MYSQL and Related Languages
- Pull information from structured databases
- Improve your knowledge of syntax
Who is the course for?
Learning Path
Before we dive into writing SQL queries, it’s important to understand what SQL and MySQL are. SQL (Structured Query Language) represents the syntax used in manipulating relational databases, whereas MySQL is a RDBMS (Relational Database Management System). In other words, MySQL uses Structured Query Language to manipulate databases.
“Querying” a database is another way of saying you want to “retrieve information from” a database. SQL queries make use of a powerful command called SELECT
, it allows us to retrieve specific information from our database.
Video 48 Min + 2 Min read to complete
The SELECT
command is where we put the attributes we’re hoping to retrieve, the FROM
command is used to signify which table we plan on selecting our attributes from, the * means “all”, and a WHERE
command is used to provide a condition to determine which specific entries from those columns we hope to retrieve. Here’s an example of one of these queries.
Video 48 Min + 2 Min read to complete
Sometimes we’re interested in querying data by categories or groups. To do this, we can make use of the GROUP BY
command. Let’s say we were interested in the number of players for each sport. We would have to count the number of players grouped by Sport. In this example, we ordered the derived table in reverse-alphabetical order.
Unions and joins are incredibly useful in querying data from tables that can be combined. A UNION
is an easy way to combine multiple SELECT
statements. Here’s an example.
Sometimes we may need to write more complex queries and make use of nested queries. A nested query, sometimes called a subquery, is a SELECT
statement within another SELECT
clause. You can think of it as a query that’s based on another query. We’ll start off with a simple example. Let’s say we wanted a list of players with the same name as a coach. We could this simply by: