Example – Wavetronix Command Translator (CMD-DT) - User Guide User Manual

Page 154

Advertising
background image

APPENDIX 153

Example

If TableOne and TableTwo both contain an “ID” column in addition to their other col-
umns, then the ID numbers can be matched up to determine how to connect the
records in TableOne with TableTwo without combining all possible records together.

You can now specify the query using the relationship between the two tables in a WHERE

clause. Since we now have two ID columns, we will reference the table names to differenti-

ate between them as well as define the relationship.

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

WHERE TableOne.ID = TableTwo.ID

This will create data rows containing only data from TableOne and TableTwo, which has

the same ID value.

Many tables may have a name column that has no relationship to name columns in other

tables. In situations where columns in multiple tables have the same name but don’t repre-

sent the same data, you will need to specify the table name before the column name in dot-

notation. If you are not specific, the database will not know which table you are referring to:

SELECT TableOne.Name, Six, TableTwo.Name, Eight from

TableOne, TableTwo

In this case, the resulting dataset will have two “Name” columns even though the data with-

in them will be different. For clarification, use the renaming method above to rename one

or both Name columns:

SELECT TableOne.Name as TableOneName, Six, TableTwo.Name

as TableTwoName, Eight from TableOne, TableTwo

You can also use an alias to save keystrokes if typing the full table name before each column

becomes cumbersome:

SELECT a.Name as TableOneName, Six, b.Name as

TableTwoName, Eight from TableOne a, TableTwo b

In this query, Six and Eight do not need table qualifiers because there are only one instance

of those column names between both tables.

Advertising