Database Guide : Database programming guide : Querying databases : Writing SELECT statements : Selecting rows from multiple tables (join operation)
Selecting rows from multiple tables (join operation)
The query in the following example joins the STAFF and ORG tables of the SAMPLE database by issuing the SQL statement directly in the code. Evaluate the code using the Inspect command:
 
"Select rows from multiple tables"
| querySpec result resultCollection connection |
resultCollection := OrderedCollection new.
connection := AbtDbmSystem activeDatabaseConnectionWithAlias: 'SampleConSpec'.
querySpec := (AbtQuerySpec new)
statement: 'SELECT ORG.DEPTNAME, ORG.DIVISION, ORG.LOCATION,
ORG.MANAGER, STAFF.DEPT, ORG.DEPTNUMB,
STAFF.NAME FROM ORG, STAFF WHERE
(ORG.DEPTNUMB = STAFF.DEPT)'.
result := connection resultTableFromQuerySpec: querySpec.
result do: [:eachRow | resultCollection add: (eachRow asString)].
^resultCollection.
 
Last modified date: 01/29/2015