SQL: SELECT Statement and Basic Queries

College Depth 6 in the knowledge graph I know this Set as goal
Unlocks 55 downstream topics
SQL SELECT query retrieval

Core Idea

The SELECT statement is the primary SQL command for retrieving data from one or more tables. It specifies which columns to retrieve (projection) and which rows satisfy conditions (selection). SELECT statements form the basis of all data queries and reporting.

Explainer

If you have studied the relational data model, you know that a database organizes data into tables — rows of records, each with named columns. The SELECT statement is how you ask a relational database to give you back some or all of that data. Every SQL query you will ever write starts here.

The minimal form of a SELECT is: `SELECT column1, column2 FROM table_name;`. The keyword SELECT is followed by a comma-separated list of column names you want to retrieve — this is *projection*, restricting the result to only the columns you care about. If you want every column, you can write `SELECT *`, but this is generally avoided in production code because it returns more data than needed and breaks if columns are added or reordered later. After FROM, you name the table to query. The semicolon ends the statement.

Think of the columns after SELECT as deciding *what shape* your result has (which attributes), and the rest of the query as deciding *which rows* to include. A query like `SELECT name, salary FROM employees` will return one row per employee — just those two columns — in an unspecified order. The database does not sort rows or filter them unless you add ORDER BY or WHERE clauses (topics you will study next).

One detail that surprises many beginners: SQL is declarative, not procedural. You describe *what data you want*, not *how to find it*. The database engine decides the physical execution plan — whether to scan the whole table, use an index, or fetch pages in parallel. This is what makes SQL so powerful: you express the intent, and the engine optimizes the execution.

A crucial point from the relational model: the result of a SELECT is itself a table — a new set of rows and columns produced by the query. This is called a *derived relation*, and it means you can use query results as inputs to other queries (subqueries), or reason about them with the same relational algebra tools you used to understand tables in the first place.

Practice Questions 3 questions

Prerequisite Chain

Longest path: 7 steps · 17 total prerequisite topics

Prerequisites (2)

Leads To (13)