OSSQL.002: SELECT — Choosing Columns, Reading Rows, SELECT *, and FROM

A diverse group of developers collaborating around a laptop in a warm modern workspace.

Elementary Overview

SELECT is the SQL statement used to ask a database for data. A basic query says which values you want returned and, usually, which table those values should come from. The database evaluates the query and gives you a result set containing zero or more rows.

This lesson follows OSSQL.001: Relational Databases and Tables. That lesson introduced rows, columns, tables, keys, and relational structure. OSSQL.002 now focuses on retrieving data with SELECT. Filtering with WHERE is intentionally left for the next SQL lesson.

What You Should Learn

  • What a SELECT statement returns.
  • How the select list controls which columns appear in the result.
  • How FROM identifies the table or source being queried.
  • How to retrieve one column or several columns.
  • What SELECT * means.
  • Why explicitly naming columns is often clearer than using *.
  • How SELECT can evaluate expressions as well as stored columns.
  • Why returned row order should not be assumed without an ordering clause.
  • Why a normal SELECT reads data rather than changing stored rows.

SELECT Produces A Result Set

The SQLite documentation describes SELECT as the statement used to query a database and notes that its result contains zero or more rows with a fixed number of result columns. PostgreSQL similarly defines SELECT as a command that retrieves rows from tables or views.

Think of a result set as a temporary answer produced by the query. If a table named customers contains columns such as customer_id, name, city, and email, a query can choose only the parts needed for the current task.

The Select List Chooses Output Columns

The expressions written between SELECT and FROM form the select list. In a simple query such as SELECT name FROM customers;, the result has one output column: name.

To return more than one column, separate them with commas. For example, SELECT name, city FROM customers; asks for two output columns for each returned row.

The order of expressions in the select list also controls the order of the output columns. SELECT city, name FROM customers; produces a result with city before name.

Giraffe Academy — “Basic Queries | SQL | Tutorial 10.” This focused lesson demonstrates SELECT *, selecting named columns, and the basic SELECT ... FROM ... query shape.
Four developers collaborating around a laptop in a cozy modern technology workspace.
Original BitcoinVersus.Tech lesson image for OSSQL.002.

FROM Identifies The Data Source

In a table query, FROM identifies the source relation. The query SELECT name FROM customers; can be read as: return the name column from the table named customers.

This distinction matters because the database needs to know both what values to produce and where those values come from. The select list answers the first question; the FROM clause answers the second.

Later lessons will expand FROM to cover joins, aliases, subqueries, and other sources. For now, use one table and make the relationship between the requested columns and their table explicit.

r/SQL discussion: developers discuss the practical relationship between writing the SELECT list and identifying the source table with FROM.

What SELECT * Means

The asterisk is a wildcard in the select list. SELECT * FROM customers; requests all columns made available by that table source.

This is convenient when exploring a small table or learning its shape. It can also be useful during quick troubleshooting when you genuinely need every column.

For application code and long-lived queries, explicitly naming the columns you need is often clearer. A query such as SELECT customer_id, name, city FROM customers; documents its intended output and does not automatically begin returning newly added table columns later. Requesting fewer columns can also reduce unnecessary data transfer when a table is wide.

SELECT Can Return Expressions

The select list is not limited to stored column names. SQL can evaluate expressions. For example, SELECT 2 + 2; returns a calculated value even without reading a table.

When a table is present, expressions can be based on column values. A later lesson will cover aliases and more useful expression patterns. The important idea for now is that SELECT describes the values that should appear in the query result, whether those values come directly from columns or are computed.

SELECT Normally Reads Instead Of Modifying

A normal introductory SELECT is a read operation. SQLite’s language reference explicitly notes that a SELECT statement does not make changes to the database. This makes SELECT the natural first SQL statement to practice after learning table structure.

SQL also has statements such as INSERT, UPDATE, and DELETE that change stored data. Those are different operations and deserve their own lessons and safety habits.

Returned Rows Can Include Duplicates

If several source rows contain the same selected value, a normal SELECT can return that value more than once. Suppose five customer rows contain the city Seattle. A simple SELECT city FROM customers; can therefore contain several rows whose visible result is the same city name.

Do not assume that querying a single column automatically produces a unique list. SQL has tools for duplicate handling, but those are separate concepts from the basic SELECT operation introduced here.

Do Not Assume Row Order

A result can look consistently ordered during testing and still have no guaranteed order. PostgreSQL and SQLite both document that explicit ordering is a separate part of query behavior. Without an ordering clause, the database may return rows in whatever sequence its execution plan produces.

For this lesson, simply remember: retrieving rows and ordering rows are different jobs. A later SQL lesson will cover ORDER BY directly.

Read A Basic SELECT From Left To Right

The query SELECT customer_id, name FROM customers; can be read in plain language as: “return the customer ID and name columns from the customers table.”

The SQL engine’s internal logical processing is more nuanced than the written left-to-right order, but beginners should first become fluent in recognizing the visible statement structure: SELECT, output expressions, FROM, and the source table.

Common Beginner Mistakes

  • Forgetting the table source: if a selected column belongs to a table, the query normally needs the appropriate FROM source.
  • Misspelling a column name: verify the table schema instead of guessing.
  • Requesting every column automatically: use * when it genuinely fits, not as a permanent substitute for understanding the schema.
  • Expecting SELECT to remove duplicates: ordinary selection can preserve repeated values.
  • Assuming row order: visible order during one run is not a guarantee.
  • Mixing filtering into this concept too early: first become comfortable selecting columns and reading results; WHERE comes next.

Mini Lab

  1. Use the table you created or practiced with in OSSQL.001.
  2. Run a query that selects one named column.
  3. Run a query that selects two named columns.
  4. Reverse those two column names and observe the output-column order.
  5. Run SELECT * against the same table and compare the result.
  6. Write a query that selects only the columns you would actually need for a simple contact list.
  7. Run SELECT 2 + 2; and observe that SELECT can produce an expression result without reading a stored column.
  8. Look for repeated values in one selected column and confirm that duplicates can appear.
  9. Run the same query more than once, but do not treat the visible row sequence as guaranteed ordering.

Knowledge Check + Answers

  1. What is SELECT used for? Retrieving or computing values that form a query result.
  2. What is the select list? The expressions between SELECT and FROM that define the output columns.
  3. What does FROM identify? The table or other data source used by the query.
  4. What does SELECT * request? All columns available from the source in that select context.
  5. Why explicitly name columns? It makes the intended result clearer and avoids returning unnecessary or newly added columns automatically.
  6. Can SELECT compute values? Yes. The select list can contain expressions as well as stored columns.
  7. Does a normal SELECT modify stored rows? No; introductory SELECT queries read or compute results.
  8. Does SELECT automatically remove duplicate values? No.
  9. Can you rely on row order without an ordering clause? No.

Primary References

Elementary Review

SELECT asks a database to return values. Name the columns or expressions you want after SELECT, identify the source with FROM, use * only when retrieving every column genuinely makes sense, and never confuse the visible order of returned rows with guaranteed ordering.

The next SQL curriculum lesson is OSSQL.003: WHERE, which will introduce filtering rows by conditions.

Editor’s Note

The featured image is original artwork created specifically for OSSQL.002 and is not reused in the body. The lesson uses a separate original body image and native responsive Gutenberg media embeds.

BitcoinVersus.Tech content is provided for informational and educational purposes.

Leave a Reply