Database Reference
In-Depth Information
The statement returns one row in the result set with the words Hello World .
The From clause
The Select statement is most often used with the From clause. The From clause allows you to
specify the tables and views you would like to retrieve data from. Here's how you use a From clause
with a Select statement:
Select AccountType, Operator
From dbo.DimAccount
After you add a From clause in your Select statement, you can call out specific columns you want
to return in the output and ask for all columns using the * wildcard:
Select *
From dbo.DimAccount
You can mix columns and constants in your Select statement to produce more sophis-
ticated outputs. You can also give aliases to columns or constants by adding a name
after each one. Here Hello World is repeated in each row in your output and the
name of that column is MyAlias . The column Operator is also renamed to
OperatorName .
Note
Select AccountType, Operator OperatorName, 'Hello World'
MyAlias
From dbo.DimAccount
Joins basics
The From clause in your query can be extended and made more sophisticated with joins. Joins allow
you to bring data from multiple related tables in your database and gives you fine control over how
to relate those tables together. There are several types of joins in SQL; in this section we go over the
three basic ones:
Inner: This is the most often-used join type and, as shown in Figure 9-1, it returns the inter-
sections of two tables or datasets.
 
Search WWH ::




Custom Search