Hello, Data! Meet SQL
Learn the fundamentals of SQL to efficiently query and filter data stored in relational databases.
Beyond files and APIs, data is often stored in relational databases—systems designed for efficient, structured storage and retrieval. Relational databases store data in tables, like a spreadsheet, with rows and columns. But unlike a single file, databases can connect multiple tables, enforce data consistency, and efficiently handle huge volumes of records.
To interact with and fetch data from these databases, we use Structured Query Language (SQL), the primary tool for interacting with relational databases. At its core, SQL lets us select the information we need, specify where it comes from, and narrow down results to exactly what’s relevant.
In this lesson, we’ll explore the fundamental building blocks of SQL queries—how to select data, apply filters, and return only what’s relevant.
Sample data: Employees table
Let’s start with a simple example table called employees to understand how SQL works. It stores information about employees in a company, including their ID, name, department, hire date, and salary.
EmployeeID | Name | Department | HireDate | Salary |
1 | Alice Johnson | Engineering | 2020-03-15 | 85,000.00 |
2 | Bob Smith | Marketing | 2019-07-22 | 65,000.00 |
3 | Carol Martinez | Sales | 2021-01-08 | 72,000.00 |
4 | David Liu | Engineering | 2018-11-02 | 95,000.00 |
5 | Eva Gómez | HR | 2022-05-16 | 58,000.00 |
6 | Frank O’Connor | Finance | 2017-09-30 | 78,000.00 |
7 | Grace Patel | Engineering | 2023-02-12 | 80,000.00 |
8 | Hiro Tanaka | Support | 2020-12-01 | 60,000.00 |
9 | Isabella Rossi | Marketing | 2021-06-25 | 67,000.00 |
10 | Arya Stark | Sales | 2019-04-10 | 71,000.00 |
Selecting data: The SELECT
and FROM
clauses
Two SQL clauses, SELECT
and FROM
, are essential when querying a database. They work together to tell the database what data we want and where to find it.
SELECT
is how we specify the exact columns—or pieces of information—we want to see in our results. For example, if we only care about employee names and salaries, we tell SQL to select only those columns.
But data doesn’t float in space—it lives inside tables. That’s where FROM
comes in. It tells SQL which table to pull the data from. As databases often contain many tables, we must specify the source.
Together, SELECT
and FROM
answer two key questions: