
152 APPENDIX
SELECT * from TableTwo WHERE Five < 10 AND Seven >= 50
SELECT * from TableOne WHERE Two = ‘Hello’ OR Two =
‘World’
ere is no limit to the number of AND or OR clauses that can be attached together.
Renaming Columns
Renaming columns for compatibility with other operations is a simple task that can be done
by using an AS clause followed by the new column name:
SELECT One, Two as NewTwo, Three, Four as NewFour from TableOne
e above query will return all four columns from TableOne but with the names One,
NewTwo, ree and NewFour. Renaming can also be used in the duplicate column situa-
tion where columns are used more than once:
SELECT Two, Three, Four, Two as NewTwo from TableOne
is query results in two exact copies of column Two, but with dierent names.
Selecting Columns from Multiple Tables
Combining one or more columns from separate tables into one dataset is done by listing the
columns from both tables together in the column listing and then adding each table name
aer the FROM keyword, separated by commas:
SELECT Two, Four, Six, Eight from TableOne, TableTwo
is method of selecting is usually not very useful. TableOne and TableTwo will usually
have dierent numbers of rows, and the database doesn’t recognize any relationship be-
tween the two tables, so the query will create new data rows based on all possible combina-
tions of TableOne and TableTwo columns.
Example
If TableOne has two data rows and TableTwo has three, the above query would return
six data rows. The six data rows will contain the six possible combinations of the two
TableOne rows and three TableTwo rows.
e above query will work if this is the desired output. However, you will usually only be
querying data from multiple tables if there is a clearly dened relationship between them.
In this case, you will need to specify that relationship in the query.
Kommentare zu diesen Handbüchern