beautypg.com

Renaming columns, Selecting columns from multiple tables – Wavetronix Command Translator (CMD-DT) - User Guide User Manual

Page 153

background image

152

APPENDIX

SELECT * from TableTwo WHERE Five < 10 AND Seven >= 50

SELECT * from TableOne WHERE Two = ‘Hello’ OR Two =

‘World’

There 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

The above query will return all four columns from TableOne but with the names One,

NewTwo, Three 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

This query results in two exact copies of column Two, but with different 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

after the FROM keyword, separated by commas:

SELECT Two, Four, Six, Eight from TableOne, TableTwo

This method of selecting is usually not very useful. TableOne and TableTwo will usually

have different 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.

The 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 defined relationship between them.

In this case, you will need to specify that relationship in the query.