SQL for Excel Users
Introduction to SQL
What is SQL?
SQL stands for Structured Query Language. Think of it as the language you use to communicate with a database. Just like you use English to ask a friend a question, you use SQL to ask a database to store, change, or give you information. It’s the standard for managing data, and it's been around for decades because it's powerful and relatively easy to read.
SQL is designed to manage data held in a relational database management system, or RDBMS. Essentially, its main job is to let you get information in and out of a database.
Databases and Tables
Before we dive into the language itself, let's clarify what we're talking to. A database is an organized collection of data, like a digital filing cabinet. Inside this cabinet, information isn't just thrown in randomly. It's stored in tables.
A table organizes data into rows and columns, much like a spreadsheet. Each column represents a specific type of information (like a name or email address), and each row represents a single record (like one specific customer).
| CustomerID | FirstName | LastName | City |
|---|---|---|---|
| 1 | Maria | Anders | Berlin |
| 2 | Ana | Trujillo | Mexico City |
| 3 | Antonio | Moreno | Mexico City |
In this example, Customers is the table. CustomerID, FirstName, LastName, and City are the columns. The row for Maria Anders is a single record. This structure is what makes databases so efficient. SQL is the tool we use to interact with tables like this one.
The Basic Commands
While SQL has many commands, you can accomplish most fundamental tasks with just four. These are often referred to by the acronym CRUD, which stands for Create, Read, Update, and Delete.
The SQL commands for these operations are
INSERT,SELECT,UPDATE, andDELETE.
Let's look at each one.
SELECT
verb
Retrieves data from a database.
The SELECT command is used to fetch data. You tell it which columns you want and from which table. If you wanted to get the first and last names of all your customers, you would write:
SELECT FirstName, LastName
FROM Customers;
This query would return a list of all the first and last names from the Customers table.
INSERT
verb
Adds new data into a database.
To add a new record, you use the INSERT INTO command. You specify the table, the columns you want to fill, and the values you want to add. Let's add a new customer:
INSERT INTO Customers (FirstName, LastName, City)
VALUES ('John', 'Smith', 'London');
This adds a new row to our Customers table for John Smith.
UPDATE
verb
Modifies existing data within a database.
What if a customer moves? The UPDATE command lets you change existing records. It's crucial to use a WHERE clause to specify which record to update. Otherwise, you'll update every single row in the table!
Let's say Maria Anders moves to Frankfurt.
UPDATE Customers
SET City = 'Frankfurt'
WHERE CustomerID = 1;
This command finds the customer with CustomerID 1 and changes their city to Frankfurt.
DELETE
verb
Removes existing data from a database.
Finally, the DELETE command removes records. Just like with UPDATE, the WHERE clause is essential to ensure you only remove the data you intend to. If you forget it, you could delete everything in your table.
To remove the customer Antonio Moreno, you would write:
DELETE FROM Customers
WHERE CustomerID = 3;
And just like that, the record is gone.
Why SQL Matters
In a world driven by data, the ability to access and understand it is a superpower. SQL is the key that unlocks that ability. It allows analysts, marketers, and decision-makers to ask complex questions of their data and get clear answers without needing to sift through thousands of spreadsheet rows manually.
Whether you're finding your top-selling products, identifying your most valuable customers, or analyzing website traffic, SQL provides a direct path to the insights hidden in your data. Mastering these four basic commands is the first step toward harnessing that power.
What does SQL stand for?
In a relational database, data is organized into tables, which are made up of what two components?
With these basics, you now have a solid foundation for working with databases.