Lesson 1 previewed the four statements this module is built around and promised that writing SELECT statements against VirtualBookShelf's own data would start here, in this lesson, rather than staying a preview. That promise is kept now. This lesson's objective is narrow and specific: write a SELECT statement that retrieves every row from a single table.
Narrow is deliberate. SQL Server 2025 supports far more than what follows here, grouping, ranking, filtering on patterns, even filtering by semantic similarity for AI-driven search, and this course's own VirtualBookShelf database will eventually be queried in richer ways than a plain SELECT. None of that belongs in this lesson. Every one of those more advanced capabilities builds on the same foundation this lesson lays: a statement that names a table and asks for its rows. Get that foundation solid first, and everything SQL Server adds on top of it, including whatever this course covers later, makes sense as an extension of something already understood rather than a fresh, unrelated skill.
Write SELECT statements that retrieve all rows from a single table. The SELECT statement is the most basic element of SQL. It is used to specify the data you want to retrieve from a specified database table or tables. In its most simple form, the SELECT statement requests the data in a single table, no joins, no filtering, no sorting, just every row and whichever columns you name.
SQL Syntax
Like all languages, SQL has a required syntax. The following diagram describes a simple SELECT statement's syntax:
SQL SELECT Statement Syntax
SELECT arguments FROM table
The SELECT statement defines the query and specifies the columns of data to get from the specified table.
The SELECT statement begins the query definition.
The arguments specify the columns of data to retrieve.
FROM specifies the table.
The table is the table name.
SQL keywords, such as SELECT, can be upper, lower, or mixed case. However, the convention, and the style every SQL statement in this course follows, is to use all upper case for keywords and leave column and table names in whatever case they were created with. This isn't a rule SQL Server enforces; a lowercase select runs exactly the same as an uppercase SELECT. It's a readability convention, the same way this course's C# code follows its own capitalization conventions for class names and properties, so that a glance at a statement separates the SQL language itself from the names of the things it's operating on.
One or more column names can be specified in a SELECT statement's argument list. If more than one name is specified, each must be separated by a comma. When the columns are later displayed, they will be displayed in the order they are specified in the argument list, not the order the table's columns happen to be defined in. The following SQL statement returns three fields from VirtualBookShelf's own Inventory table.
SELECT BookID, Title, Author FROM Inventory
View the following result set to see what this query returns.
BookID Title Author
1 The Last Lighthouse Bennett
2 Coastal Kitchens Alvarez
3 Deep Winter Castellano
4 Algorithms Simplified Chen
5 Building With Stone Whitfield
SQL Result Set consisting of 1) BookID 2) Title 3) Author
Notice that the result set has exactly three columns, in exactly the order they were listed in the argument list, BookID, then Title, then Author, even though Inventory itself also has ISBN, Price, and QuantityOnHand columns. A SELECT statement's argument list controls what comes back; nothing else about the table's structure changes because of it.
If you want to get all the columns from a table, you do not have to specify all the column names in the argument list. You can use the asterisk ( * ) instead. The asterisk is like a wildcard character that means everything. For example:
SELECT * FROM Inventory
Running that statement against VirtualBookShelf's Inventory table returns every column, BookID, Title, Author, ISBN, Price, and QuantityOnHand, for every row, in the order the table itself was created with. The asterisk is convenient for a quick look at everything in a table, exactly the kind of ad hoc check this course runs in Azure Data Studio, but it comes with a real trade-off worth knowing now rather than discovering later: naming the columns you actually need, the way the first example did, tells SQL Server precisely what to retrieve, which matters once a table grows large or an application only needs two or three of its columns rather than all six. SELECT * is a fine habit while learning; naming columns explicitly is the better habit once VirtualBookShelf's own Razor Pages start calling these statements for real.
A SELECT Statement Is a Declarative Request
Lesson 1 drew a distinction between declarative and procedural thinking: a procedural approach, the kind the legacy VBScript version of this course relied on, walks through rows one at a time with a loop, while a declarative statement simply states what's wanted and leaves SQL Server to decide how to get it. SELECT BookID, Title, Author FROM Inventory is the plainest possible example of that idea. The statement names a table and a set of columns; it says nothing at all about how SQL Server should locate the rows, whether to scan the whole table, use an index, or anything else. That decision belongs entirely to SQL Server's query optimizer.
This matters even at this introductory level, because it explains why the statement looks the way it does. There's no loop counter, no "for each row" instruction, no step that says "open the table" before a step that says "read the first row." The statement is a single sentence describing a result, and the result, not a sequence of steps, is the whole point. Every statement the rest of this module introduces, WHERE, sorting, INSERT, UPDATE, DELETE, follows the same pattern: each one describes what should happen to the data, never how to step through it row by row.
The Same Query, Three Ways
Module 2's conclusion page compared one query across SQL, ADO.NET, and Entity Framework Core to show that all three ultimately send the same statement to SQL Server. This lesson's own query fits that comparison just as well:
-- Raw SQL, written and run directly in Azure Data Studio
SELECT BookID, Title, Author FROM Inventory;
// ADO.NET, built in Module 2, Lesson 6
using var cmd = new SqlCommand("SELECT BookID, Title, Author FROM Inventory;", connection);
using var reader = cmd.ExecuteReader();
// Entity Framework Core, built in Module 2, Lesson 7
var books = context.Inventory
.Select(b => new { b.BookID, b.Title, b.Author })
.ToList();
Running the first version directly in Azure Data Studio, the way this lesson does, is what makes the second and third versions make sense. Both of them are, underneath, generating and sending a statement with the exact same shape as the one typed by hand here.
Writing and Running This Statement Yourself
Lesson 1 named the tool this course uses for exactly this: Azure Data Studio, connected to VirtualBookShelf's SQL Server 2025 database. Open a new query window there, type either statement above, and run it. Both statements return immediately, there's no C# project to build, no Razor Page to compile, just the raw statement and the rows it matches.
Concretely, that means four steps: open Azure Data Studio, connect to the VirtualBookShelf database using the connection already configured in Module 2, open a new query window against that connection, and type the statement. A keyboard shortcut or a toolbar "Run" button executes it, and the result set appears in a grid below the query window, one row per matching record, one column per argument in the SELECT list. Nothing about this workflow changes from one statement to the next; every lesson in this module runs its examples through exactly these same four steps.
This is also a good moment to notice what a SELECT statement does not do. Neither statement above changes a single row in Inventory. SELECT only reads; it never adds, updates, or removes data, no matter how it's phrased or how many times it runs. That's worth saying plainly, because the next three lessons in this module introduce statements that do change data, and the difference between a statement that only looks and one that changes something is a distinction worth having clear before INSERT, UPDATE, and DELETE show up.
Statement Conventions Worth Adopting Now
A few small conventions make SQL easier to read and write, even though SQL Server doesn't strictly require any of them for a single statement like this lesson's.
A semicolon at the end of a statement marks where it stops. SQL Server will usually run a single statement typed into Azure Data Studio without one, but the moment a query window holds more than one statement, the semicolon is what tells SQL Server where the first one ends and the next one begins. Every statement from this point forward in this course ends with one, SELECT BookID, Title, Author FROM Inventory;, as a habit worth building from the start rather than adding later once it starts to matter.
SQL also supports comments, text SQL Server ignores entirely when it runs a statement. A double hyphen, --, comments out everything to the end of that line; a /* ... */ pair comments out everything between them, even across several lines. Comments are useful for exactly the reason they're useful in C#: leaving a short note about why a statement is written the way it is, for whoever reads it next, including yourself.
-- Retrieve a book's basic catalog information
SELECT BookID, Title, Author FROM Inventory;
Whitespace, meanwhile, is almost entirely free-form. SQL Server doesn't care whether a statement is typed on one line or spread across several, or how many spaces separate one word from the next. SELECT BookID, Title, Author FROM Inventory; and a version of the same statement with each column on its own line run identically. Longer statements later in this course, once a WHERE clause and an ORDER BY clause are both in play, will take advantage of that freedom to stay readable rather than running into a single long line.
Reading a Result Set That Includes Missing Values
VirtualBookShelf's Customer table, built back in Module 2, Lesson 2, has a column, Phone, that allows a missing value: its definition is Phone nvarchar(20) NULL, in contrast to every other column in that table, which is defined NOT NULL. Running SELECT FirstName, LastName, Phone FROM Customer; against a table where some customers never provided a phone number returns a row for every customer regardless, with NULL shown in place of a value for whichever rows don't have one.
NULL is worth understanding clearly this early, because it isn't the same thing as an empty string or a zero. It means the value is genuinely unknown or not present at all, which is why comparing a column to NULL with an ordinary equals sign doesn't work the way comparing it to an actual value does, a detail the next lesson's WHERE clause will need to account for directly. For now, the useful fact is simpler: a plain SELECT statement, with no filtering, returns every row exactly as stored, missing values included, exactly the way this lesson's examples have shown.
A Few Common Questions
Does the order of columns in the argument list have to match the order they appear in the table? No. A SELECT statement's argument list controls the order columns are returned in, independent of how the table itself was defined. SELECTAuthor, Title FROM Inventory returns Author first and Title second, even though Inventory was created with Title listed before Author.
Is there a limit to how many rows a plain SELECT * FROM table statement can return? Not from the statement itself. It returns every row currently in the table. VirtualBookShelf's Inventory table only has a handful of rows right now, so this isn't noticeable yet, but a production bookstore's inventory table could hold thousands of rows, and a plain SELECT with no filtering returns all of them. Narrowing that down is exactly what next lesson's WHERE clause is for.
Can a SELECT statement reference a column that doesn't exist in the table? No, and SQL Server won't guess at what was meant. A typo in a column name, Titel instead of Title, for instance, causes the statement to fail with an error naming the invalid column, rather than silently returning something unexpected. A rejected statement with a clear error is the normal, expected result of a typo, not a sign that something is broken.
Does SQL Server 2025 support more than this basic form of SELECT? Yes, considerably more. SQL Server 2025 adds native support for regular-expression filtering, a native JSON data type, and vector similarity search for AI-driven applications, well beyond what this lesson covers. None of that has a foothold in VirtualBookShelf's schema yet, and none of it is needed to retrieve rows from Inventory, so this lesson stays with the basic form: naming columns, or using the asterisk, against a single table.
Why does this lesson use Inventory instead of Customer for its examples? Either table works for a plain SELECT, the statement's behavior doesn't depend on which table it's run against. Inventory was chosen here because its six columns, BookID, Title, Author, ISBN, Price, and QuantityOnHand, give a slightly richer result set to look at than Customer's five, which makes the difference between naming three columns and using the asterisk easier to see.
Can the same column be listed twice in a single SELECT statement's argument list? Yes, and SQL Server returns it twice, once for each time it was listed. SELECT Title, Title, Author FROM Inventory; is valid and runs without error; it simply isn't useful, since the second Title column in the result set repeats information the first one already provided.
Does it matter whether a statement is typed on one line or several? No. As the conventions section above covers, SQL Server treats a statement the same way regardless of line breaks or extra spacing. SELECT BookID, Title, Author FROM Inventory; and the same statement split across three lines, one clause per line, run identically; the second form simply becomes easier to read once a statement grows longer than this lesson's examples.
What's Ahead
This lesson covered the most basic form SQL has: a SELECT statement that names the columns it wants, or uses the asterisk to request all of them, and retrieves every row in a single table with no filtering at all.
In the next lesson, you will learn how to use the WHERE clause to select specific rows from a database, narrowing a SELECT statement from every row in Inventory or Customer down to only the rows that match a particular condition, the parameterized search Lesson 1 named as this module's second objective.
Everything built in this lesson carries forward unchanged. The WHERE clause adds to a SELECT statement, it doesn't replace anything about how one is written: the same argument list, the same FROM clause, the same table names, with one more piece added onto the end. The lesson after that adds ORDER BY to control the order results come back in, and the lessons following it move on to INSERT, UPDATE, and DELETE, the three statements that change a table's data rather than only reading it.