When you create more than one join between a pair of tables in a SQL statement, you do so by providing an alias for one of the tables. For example, suppose an inventory items table has general ledger (GL) account numbers for both expense (when the item is purchased) and revenue (when the item is sold). A SQL statement that shows the inventory item description and the GL account names is:

select ITEMS.NAME, GLACCOUNT.NAME, EXPENSE.NAME 
  from ITEMS
  inner join GLACCOUNT
    on ITEMS.REVACCOUNT = GLACCOUNT.ACCOUNTNUM
  inner join GLACCOUNT EXPENSE
    on ITEMS.EXPACCOUNT = EXPENSE.ACCOUNTNUM

Specifying EXPENSE as the alias for the GLACCOUNT table when it's used for expense accounts allows the database engine to handle the two uses for this table.

Stonefield Query provides the ability to define aliases for tables by defining a "subtable" of a table. A subtable is really just a way of assigning an alias to a table so it can be used more than once in a SQL statement, but provides some additional capabilities as well:

Subtables aren't just useful for multiple relationships between a pair of tables; they can also be used for self-joins. For example, you may have an Employees table that includes a ManagerID field which contains the ID for another employee record representing the employee's manager. In this case, create a subtable of Employees called Managers and define a relationship between them matching the ManagerID field from Employees with the ID field from Managers. You may also want only certain fields in Managers to be available, such as their name, since salary, department, and other fields can be obtained from the appropriate Employees record. You may also set a Filter for Managers, something like Managers.IsManager = .T.

To create a subtable for a table, select the table in the TreeView and choose the Create Subtable function from the Objects menu, the shortcut menu, or from the drop-down list for the Create button. Stonefield Query Studio creates a copy of the table and all of its fields, with a default name of "Subtable" (where table is the name of the original table). You are prompted if you want to copy the relations for the existing table to the subtable. Subtables have a different icon in the TreeView () and a different set of properties.

In addition to the usual properties for tables, subtables also have the following properties:

Stonefield Query may automatically create subtables when it creates the meta data for a database; see the Adding a Database to the Data Dictionary topic for details.

See Also
Adding a Database to the Data Dictionary | Table Properties