Module 1: Mastering the SQL SELECT Statement (A Step-by-Step Guide)

Module 1

The SELECT Statement & Selecting All Columns

Your first real SQL command — hands-on, step by step

SELECT * FROM students; -- "give me every column, for every row, in this table"

Every SQL journey starts in the same place: the SELECT statement. It's the command you'll type more than any other — and once it clicks, everything else in SQL starts to make sense.

This lesson is fully hands-on. You'll open your own database tool, build a small practice table, and run your first real queries — including the most common one of all: selecting every column with *. By the end, you'll have working practice code, a self-graded quiz, and homework to lock it in.

Introduction

What This Lesson Covers

🎯 Objective

By the end of this lesson, you'll be able to write a correct SELECT statement from memory, understand exactly what * does, and confidently pull every column from any table in your own database.

⚠️ What to Watch Out For

The * shortcut is convenient, but it has real downsides once you leave the practice table:

  • It's slower on large tables. Pulling every column — including ones you don't need — wastes memory and network bandwidth on a production database.
  • It hides what your query actually depends on. If someone adds a new column to the table later, your SELECT * query silently starts returning it too, which can break code that expects a fixed set of columns.
  • It's fine for learning and quick checks — just don't build the habit of using it in real applications. We'll cover selecting specific columns in Module 2.

💡 Important to Know Before You Start

Important

SQL keywords like SELECT and FROM aren't case-sensitive — select works exactly the same as SELECT. This lesson writes them in uppercase purely as a readability convention, which you'll see in almost every professional codebase.

Requirements

What You'll Need to Follow Along

This lesson works the same way no matter which computer you're on:

WindowsXAMPP or MySQL installed and running — see the links below if you haven't set this up yet.
macOSXAMPP for Mac, or MySQL installed via Homebrew — either works fine for this lesson.
LinuxMySQL or MariaDB installed via your package manager (e.g., apt install mysql-server).
Any OS + browser onlyNo local install? Use a free playground like DB Fiddle or SQLBolt — the syntax in this lesson works the same everywhere.
Haven't installed anything yet?

Follow How to Install XAMPP Step by Step or How to Install MySQL Step by Step first, then come back here.

Practice

Let's Build It: 9 Steps

    MySQL (CLI)
  1. Open MySQL (CLI) or phpMyAdmin

    You can follow this lesson from either tool — pick whichever you're more comfortable with.

    Command line: open your terminal and connect:

    mysql -u root -p

    phpMyAdmin: with Apache and MySQL running, open http://localhost/phpmyadmin/ in your browser, and use the SQL tab to type queries directly.

    Either way, the syntax you type is identical — SELECT doesn't care which tool sends it.

  2. Create a database, then verify it exists

    CREATE DATABASE school_practice;
    SHOW DATABASES;

    SHOW DATABASES; lists every database on your server — look for school_practice in the output to confirm it was created.

  3. Select the database, then create a table

    USE school_practice;
    
    CREATE TABLE students (
        id INT PRIMARY KEY,
        name VARCHAR(50),
        grade INT,
        country VARCHAR(50)
    );

    USE tells MySQL which database your next commands apply to — you must run this (or select it in phpMyAdmin's sidebar) before creating tables.

  4. Verify the table was created

    SHOW TABLES;
    DESCRIBE students;

    DESCRIBE students; shows every column you just created, along with its data type — a good habit before you start querying.

  5. Insert a few practice rows

    INSERT INTO students (id, name, grade, country) VALUES
    (1, 'Sokha', 90, 'Cambodia'),
    (2, 'Maria', 85, 'Spain'),
    (3, 'Wei', 78, 'China'),
    (4, 'Aiden', 92, 'USA');

    Without data in the table, there's nothing for SELECT to show you — this step gives you something real to query.

  6. Run your first SELECT statement

    SELECT * FROM students;

    You should see all 4 rows, with all 4 columns. That's it — you've just run a real SQL query.

  7. Break down the syntax, piece by piece

    PartMeaning
    SELECT"I want to retrieve data" — every read query starts here.
    *A wildcard meaning "every column" — shorthand for typing out each column name.
    FROM studentsTells the database which table to look in.
    ;Ends the statement — MySQL won't run the command without it.
  8. Understand what * actually returns

    * means "all columns, in the order they exist in the table" — not a specific list. Compare the difference:

    -- All columns (order defined by the table itself)
    SELECT * FROM students;
    
    -- Same result, written out manually
    SELECT id, name, grade, country FROM students;

    Both queries above return identical results right now — but only because you know exactly what columns exist. That's the tradeoff we flagged in the introduction.

  9. Practice on your own table

    Before moving on, try this without copying: create a second table called books with columns for id, title, and author, insert 3 rows, then run SELECT * FROM books; to confirm it works. This is the exact pattern you'll repeat in every future lesson.

Troubleshooting

Common Problems and Solutions

Problem 1: "No database selected"

You tried to create a table or run a query, but MySQL doesn't know which database to use.

SolutionRun USE school_practice; first (or click the database name in phpMyAdmin's sidebar) before running any other command.

Problem 2: "Table 'school_practice.students' doesn't exist"

Your SELECT query is pointing at a table that was never created, or the name is misspelled.

SolutionRun SHOW TABLES; to see the exact table names that exist, and check for typos — table names are case-sensitive on some systems (Linux in particular).

Problem 3: The query runs but returns an empty result

SELECT * FROM students; executes with no error, but no rows appear.

SolutionConfirm data actually exists with SELECT COUNT(*) FROM students;. If it returns 0, your INSERT statement either failed silently or was never run — re-check Step 5.

Problem 4: "You have an error in your SQL syntax"

MySQL rejects the query outright, usually pointing near a specific word.

SolutionCheck for a missing semicolon at the end of the previous statement, a missing FROM keyword, or a stray comma. Reading the error message near the highlighted word usually points straight at the typo.

Conclusion

What to Expect Next

You now know how to open a database tool, build a table from scratch, insert real data, and pull it all back out with SELECT *. That one pattern — create, insert, select — is the foundation every other SQL skill builds on.

In Module 2, we'll move past the * wildcard and learn to select specific columns, filter rows with WHERE, and sort results with ORDER BY — the next step toward writing queries that would hold up in a real job.

Homework

Before Module 2: Practice on Your Own

  1. Create a table called movies with columns id, title, year, and genre.
  2. Insert at least 5 rows of your own favorite movies.
  3. Run SELECT * FROM movies; and confirm all 5 rows appear correctly.
  4. Run DESCRIBE movies; and write down, from memory, what each column's data type means.
  5. Try to break your own query on purpose — remove the semicolon, misspell the table name — then read and understand the error message MySQL gives you.

Self-Check

Quick Quiz: Test Yourself

5 questions — instant results, no sign-up

Pick your answers, then click "Check My Answers" at the bottom.

1. Which keyword starts every query that retrieves data?

2. What does * mean in a SELECT statement?

3. Which keyword tells MySQL which table to read from?

4. What ends every SQL statement?

5. Why should you avoid SELECT * in a real production app?

FAQ

Frequently Asked Questions

Is SELECT the same in MySQL, PostgreSQL, and SQL Server?

The core syntax — SELECT ... FROM ... — works the same across almost every relational database. Small differences show up in more advanced features, but this lesson's syntax is portable everywhere.

Do I have to write SELECT in uppercase?

No. SQL keywords aren't case-sensitive, so select and SELECT behave identically. Uppercase is just a widely used convention that makes queries easier to read.

What happens if I forget the semicolon?

In the MySQL command line, the query simply won't run — it waits for more input. In phpMyAdmin's SQL tab, a single statement usually still works, but it's a habit worth building since most tools require it.

Can I use SELECT * on more than one table at once?

Yes, using a JOIN — but that's a later lesson. For now, SELECT * works on a single table at a time.

Why did my table appear empty even after I ran INSERT?

Usually because the INSERT statement had a typo or ran against the wrong database. Run SELECT COUNT(*) FROM tablename; to check how many rows actually exist.

Is phpMyAdmin better than the command line for beginners?

Neither is "better" — phpMyAdmin is more visual and forgiving while you're learning, while the command line builds muscle memory you'll need for real server work later. This lesson works identically in both.

What's the difference between SELECT * and listing column names manually?

Both return the same data today, but listing columns by name is safer long-term — your query won't unexpectedly change if someone adds a new column to the table later.

Do column names need quotes in SQL?

Not normally. Quotes (or backticks in MySQL) are only needed if a column name contains spaces or matches a reserved SQL keyword.

What does VARCHAR(50) mean in the CREATE TABLE step?

It defines a text column that can hold up to 50 characters. The number is a length limit, not a requirement — shorter text is fine too.

Can I rename a table after creating it?

Yes, using RENAME TABLE old_name TO new_name; — but that's outside the scope of this lesson.

Why is my table name case-sensitive on some systems but not others?

It depends on your operating system and MySQL configuration — Linux servers are usually case-sensitive for table names, while Windows and macOS often aren't by default. Sticking to consistent lowercase names avoids the issue entirely.

Is it safe to practice these commands on a real project's database?

Not recommended. Always practice on a throwaway database like school_practice — never run CREATE, INSERT, or DELETE commands against data you actually care about until you're confident.

What's the difference between SHOW TABLES and DESCRIBE?

SHOW TABLES; lists every table in the current database. DESCRIBE tablename; shows the columns and data types inside one specific table.

Can I delete the practice database when I'm done?

Yes — DROP DATABASE school_practice; removes it completely. Just be certain you're pointing at the practice database and not a real one before running it.

Post a Comment

Previous Post Next Post