← Back to MySQL Course | Chapter 5: Inserting & Selecting Data | Lesson 3 of 6

SELECT Statement

Introduction to SELECT

SELECT retrieves rows from a table and is the single most frequently used SQL statement, forming the foundation of nearly every read operation an application performs against its database.

Example: Introduction to SELECT

sql
SELECT * FROM users;

Selecting Specific Columns

Naming specific columns instead of retrieving every column reduces the amount of data MySQL has to read and transmit, which measurably speeds up queries on wide tables or over slow network links.

Example: Selecting Specific Columns

sql
SELECT name, email FROM users;

Basic Math in SELECT

You can perform arithmetic directly inside a SELECT's column list — like multiplying price by quantity — to compute derived values on the fly without altering anything stored in the table.

Example: Basic Math in SELECT

sql
SELECT name, price * quantity AS total FROM orders;

System Information Queries

SELECT can also return values with no table involved at all, such as the server's current time or version, which is a handy way to sanity-check a connection is alive.

Example: System Information Queries

sql
SELECT VERSION();

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Best Practices for SELECT

Avoiding SELECT * in production code is a widely recommended practice: fetching only the columns you actually need avoids wasted memory, network traffic, and breakage if the table's columns change later.

Example: Best Practices for SELECT

sql
-- Avoid SELECT * in production; name only the columns you need
SELECT name, email FROM users;
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.