3.1. The Basic SELECT Statement

The SELECT statement and the structures used within it form the basis for the lion's share of all the commands we will perform with SQL Server. Let's look at the basic syntax rules for a SELECT statement:

SELECT <column list>
[FROM <source table(s)> [[AS] <table alias>]
[[{FULL|INNER|{LEFT|RIGHT} OUTER|CROSS}] JOIN <next table>
[ON <join condition>] [<additional JOIN clause> ...]]]
[WHERE <restrictive condition>]
[GROUP BY <column name or expression using a column in the SELECT list>]
[HAVING <restrictive condition based on the GROUP BY results>]
[ORDER BY <column list>]
[[FOR XML {RAW|AUTO|EXPLICIT|PATH [(<element>)]}[, XMLDATA][, ELEMENTS][, BINARY base 64]]
[OPTION (<query hint>, [, ...n])]
[;]

3.1.1. The SELECT Statement and FROM Clause

The "verb" — in this case a SELECT — is the part of the overall statement that tells SQL Server what we are doing. A SELECT indicates that we are merely reading information, asopposed to modifying it.

The FROM statement specifies the name of the table or tables from which we are getting our data. With these, we have enough to create a basic SELECT statement. Fire up the SQL Server Management Studio and let's take another look at the SELECT statement we ran during the last chapter:

SELECT * FROM INFORMATION_SCHEMA.TABLES;

Let's look at what we've asked for here. We've asked to SELECT information — you can also think of this as requesting to display information. The * works pretty much as * does everywhere — it's ...

Get Professional SQL Server™ 2005 Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.