SQL: The Language of Data

A short guide to SQL basics

A Brief History of SQL

In order to know where we are, it's important to know the history. Even if it may not be directly applicable to using SQL, I'm going to nerd out for a minute anyways.

SQL, which stands for Structured Query Language, was developed in the early 1970s by Donald D. Chamberlin and Raymond F. Boyce at IBM. It was originally called SEQUEL (Structured English Query Language) and used to query IBM’s System R database.

In 1974, Chamberlain and Boyce introduced the language to the world in their article SEQUEL: A Structured English Query Language. In that paper, they proposed SEQUEL as an anlernative to SQUARE. The following quote is from that article:

"The SEQUEL language is equivalent in power to SQUARE, but it is intended for users who are more confortable with an English-keyword format than with the terse mathematical notation of SQUARE."

By 1986, SEQUEL had been renamed SQL and it became standardized by the American National Standards Institue (ANSI). Since then, there have been many updates to the language but many of the basics remain the same. Today it powers relational database management systems like MySQL, PostgreSQL, Oracle, and SQL Server.

If you are a student majoring in Data Science or just a little bit of a nerd, I highly encourage you to read this article. It may not hold extreme relevance in syntax but it is filled with insight into the language's "author's intent".

What Is a Relational Database?

A relational database organizes data into tables made of rows and columns. A table should be named according to the data contained in it (if the database was designed efficiently). Each table is like a spreadsheet, where:

Columns - describe the data stored (e.g., name, email, dob)
Rows - store actual data records (e.g., John, johndoe@email.com, 01-01-1972)

Tables can be connected using keys, such as primary and foreign keys. We will take a much closer look when we cover JOINS in a later article. However, I hope that the example below provides enough clarity to illustrate the relationships that tables can have between one another.

Example:

Customers Table

Customer_ID | First_Name | Last_Name
----------- | -----------|----------
101         | Alice      | Johnson
102         | Bob        | Smith
            

Orders Table

Order_ID | Customer_ID | Product
-------- | ------------|--------
001      | 101         | Laptop
002      | 102         | Phone
            

The columns Customers.Customer_ID and Orders.Order_ID are primary keys whereas Orders.customer_id is a foreign key.

This structure allows us to connect which customer made which order using the Customer_ID (The key exists in both tables).

SQL Syntax Basics: SELECT, FROM, WHERE

According to Chamberlain and Boyce, the core structure of a query can be described as the SELECT-FROM-WHERE block, which allows you to retrieve specific data from a database. Today it is more widely known as the SELECT statement. The statement is made up of clauses, each clause serving a dedicated purpose.

SELECT – the data being searched for.

FROM – the location of that data.

WHERE – the criteria the data must meet

SELECT

In the SELECT clause, you specify all the columns you want to retrieve from a database table. This allows you to extract specific pieces of information or nominal data relevant to your analysis.

SELECT First_Name, Last_Name

FROM

In the FROM clause, you tell the query in which table it needs to search. You can also use the FROM clause with multiple tables to combine data, but we’ll dive into joins later.

FROM Customers

WHERE

Understanding the WHERE clause is the begining of building powerful queries. It allows you to filter the data based on specific criteria.

WHERE Customer_ID = 101;

Putting It All Together

When combined, the complete query looks like this:


        SELECT First_Name, Last_Name
        FROM Customers
        WHERE Customer_ID = 101;
            

This query returns the following based on the previous table examples:


        First_Name | Last_Name
        -----------|----------
        Alice      | Johnson
            

Wrapping Up

SQL is the foundation of working with structured data. Whether you're analyzing business trends or building applications, knowing how to query data effectively is an essential skill. It requires little knowledge to get started yet it can provide tremendous value to nearly any career field.