Introduction to Databases and the SELECT Statement

Welcome to the Digital Warehouse

The SQL Analogy

Think of a database as a massive Digital Warehouse. To get information out of it, you need to know how the warehouse is organized and how to ask the manager for specific items.

Welcome to your first step in mastering data. Imagine a database is a massive digital warehouse. Inside, data is organized into tables, much like aisles in a store. Each row represents a single item, while columns store specific details about those items, like their price or description. SQL is the tool we use to talk to the warehouse manager.

Exploring the Products Table

Our Sample Database

We will use a realistic E-commerce database throughout this course. Let's look at the Products table, which stores everything our store sells.

Before we write code, let's look at our data. This is the Products table. Notice the column names at the top: product_id, product_name, category, price, and stock_quantity. Each row below these headers represents a unique product in our inventory. To get this data, we use the SELECT statement.

The SELECT Statement

The Basic Syntax

To retrieve data, you need two keywords:

Use an asterisk (*) to grab all columns at once.

To retrieve data, we use the SELECT statement. Think of it as a sentence: 'SELECT these columns FROM this table.' If you want to see every detail available, use the asterisk as a wildcard shorthand for 'all columns'. Running this query returns every single row and column in the Products table.

Selecting Specific Columns

Reducing Data Clutter

In large databases, tables can have hundreds of columns. To save time and memory, only select the columns you need by listing their names separated by commas.

Often, you don't need every piece of information. Instead of using the asterisk, you can list specific columns. By requesting only the product name and price, we reduce data clutter and make our results much easier to read. Remember to separate your column names with a comma.

Spot the Syntax Errors

SQL is picky! Look at the three queries below and click on the errors to fix them.

Even experts make mistakes. Here are three common pitfalls for beginners. Can you find the spelling error, the missing comma, and the wrong keyword order? Click the errors to fix the queries. Correct. Multiple columns need commas to separate them, but never put one after the last column. Exactly. In SQL, we always say SELECT what we want before we say FROM where it comes. Great catch! SQL won't recognize 'product_nme'—it must match the table definition exactly.

Exercise 1: Inventory Overview

Your Turn!

The warehouse manager needs a complete overview of the inventory. Write a query to retrieve all columns from the Products table.

Time for some hands-on practice. Write a query to retrieve all columns from the Products table. Type your code in the editor and click 'Run Query' to see the results.

Exercise 2: Marketing List

Marketing Request

The marketing manager only needs the product_name and category. Write a query to retrieve just these two columns from Products.

Now, let's be more specific. The marketing team doesn't need prices or IDs—just names and categories. Write the query to fetch only those two columns.

Exercise 3: Finance Audit

Finance Check

The finance team needs to check pricing and stock levels. Write a query to retrieve the product_name, price, and stock_quantity.

Final challenge for this lesson! Finance needs to see names, prices, and stock quantities. Combine everything you've learned to write this three-column query.