Back to Blog
November 28, 2024Data Fundamentals

What Is SQL?

SQL (Structured Query Language) is how you talk to databases. Pronounced "sequel" or "S-Q-L" depending on who you ask.

If a database is a library full of books, SQL is how you ask the librarian for what you need. "Find all books by this author, published after 2020, sorted by title." SQL lets you make those requests in a way the database understands.

Why SQL Matters

SQL is everywhere. It's been around since the 1970s and shows no signs of going away. Almost every company with data uses SQL somewhere:

  • Analysts write SQL to create reports
  • Data scientists use SQL to prepare data for models
  • Developers use SQL to store and retrieve application data
  • Business users run SQL queries in BI tools (often without realizing it)

Learning basic SQL is one of the highest-leverage skills for anyone who works with data.

Universal Language
Whether you're using PostgreSQL, MySQL, SQL Server, Snowflake, or BigQuery - the core SQL syntax is the same. Learn it once, use it everywhere.

Basic SQL Operations

SQL has four main operations, often called CRUD:

SELECT (Read) - Get data from the database ``` SELECT name, email FROM customers WHERE state = 'California' ``` "Give me the name and email of all customers in California"

INSERT (Create) - Add new data ``` INSERT INTO customers (name, email) VALUES ('Jane Smith', 'jane@example.com') ``` "Add a new customer named Jane Smith"

UPDATE (Update) - Change existing data ``` UPDATE customers SET email = 'new@example.com' WHERE id = 123 ``` "Change the email for customer 123"

DELETE (Delete) - Remove data ``` DELETE FROM customers WHERE last_order_date < '2020-01-01' ``` "Remove customers who haven't ordered since 2020"

Reading SQL Queries

Even if you never write SQL, being able to read it helps. Most queries follow this pattern:

``` SELECT [what columns you want] FROM [which table] WHERE [filter conditions] ORDER BY [how to sort] LIMIT [how many rows] ```

Example: ``` SELECT customer_name, total_spent FROM orders WHERE order_date >= '2024-01-01' ORDER BY total_spent DESC LIMIT 10 ```

This says: "Show me the top 10 customers by spending since January 1st, 2024."

JOINs - Connecting Tables

Real power comes from combining data across tables. That's what JOINs do.

Say you have a customers table and an orders table. To see customer names with their orders:

``` SELECT customers.name, orders.total FROM customers JOIN orders ON customers.id = orders.customer_id ```

This connects the two tables using the customer ID that appears in both.

JOINs can get complex, but the concept is simple: bring together related data that lives in different tables.

Aggregations - Summarizing Data

SQL can do math across rows:

``` SELECT state, COUNT(*) as customer_count, SUM(total_spent) as total_revenue, AVG(total_spent) as average_spent FROM customers GROUP BY state ORDER BY total_revenue DESC ```

This gives you customer count and revenue by state - the kind of summary you'd put in a report or dashboard.

SQL in Practice

You'll encounter SQL in several contexts:

BI tools (Looker, Tableau, Mode) - Many let you write custom SQL queries or show you the SQL behind visualizations.

Spreadsheet connections - Google Sheets and Excel can pull data from databases using SQL.

Data warehouses (Snowflake, BigQuery) - Where analysts spend most of their SQL time, analyzing large datasets.

Application backends - Developers write SQL (or use tools that generate it) to store and retrieve data.

Learning SQL

The basics are surprisingly approachable. You can learn enough to be useful in a few hours:

1. SELECT, FROM, WHERE - filtering data 2. ORDER BY, LIMIT - sorting and limiting results 3. COUNT, SUM, AVG - basic aggregations 4. GROUP BY - summarizing by category 5. JOIN - combining tables

Advanced SQL (window functions, CTEs, subqueries) takes longer, but most business needs are covered by the basics.

Free resources abound - SQLZoo, Mode's SQL Tutorial, and Khan Academy all offer good introductions.

SQL queries your database. Learn about how databases work and data warehouses for analytics.

---

Sources: - W3Schools: Introduction to SQL - Oracle: What Is SQL? - Mode: SQL Tutorial

Ready to Talk Data Strategy?

Let's discuss how we can help with your data challenges.

Book a Call