xHarbour Reference Documentation > Command Reference |
Merges records of two work areas into a new database.
JOIN WITH <cAlias> ; TO <cDatabase> ; FOR <lForCondition> ; [FIELDS <fieldNames,...>]
The JOIN command merges records from the current, or primary, work area with records from a secondary work area into a new database. For each record in the primary work area, all records of the secondary work area are scanned and the FOR condition is evaluated. When this evaluation is .T. (true), a new record is added to the target database.
Records marked for deletion in either work area are ignored when SET DELETED is ON. If this setting is OFF, all records are processed in both work areas. A deletion flag, however, is not transferred to the target database. That is, no record in the target database is marked for deletion.
Caution: The JOIN command can turn out to be extremely time consuming since the FOR condition is evaluated Lastrec() in primary work area times Lastrec() in secondary work area. Use this command with care, especially when merging large databases.
See also: | DbJoin(), DbSetRelation(), INDEX, SET RELATION |
Category: | Database commands |
// This example joins Customer.dbf with Invoices.dbf to produce Sales.dbf PROCEDURE Main USE Invoices ALIAS Inv NEW USE Customer ALIAS Cust NEW JOIN WITH Inv TO Sales ; FOR CustNo = Inv->CustNo ; FIELDS CustNo, FirstName, LastName, Inv->Total CLOSE DATABASE RETURN
http://www.xHarbour.com