Joins between remote tables

The following figure illustrates proxy tables on a local database server that are mapped to the remote tables Employees and Departments of the SAP Sybase IQ sample database on the remote server RemoteSA.



     The remote tables and proxy tables are mapped.

You can use joins between tables on different SAP Sybase IQ databases. The following example is a simple case using just one database to illustrate the principles.

Example

Perform a join between two remote tables:

  1. Create a new database named empty.db.

    This database holds no data. It is used only to define the remote objects, and to access the SAP Sybase IQ sample database.

  2. Start a database server running the empty.db. You can do this by running the following command:

    iqsrv16 empty
  3. From Interactive SQL, connect to empty.db as user DBA.

  4. In the new database, create a remote server named RemoteSA. Its server class is SAODBC, and the connection string refers to the SAP Sybase IQ 16 Demo ODBC data source:

    CREATE SERVER RemoteSA
    CLASS 'SAODBC'
    USING 'SAP Sybase IQ 16 Demo';
  5. In this example, you use the same user ID and password on the remote database as on the local database, so no external logins are needed.

    Sometimes you must provide a user ID and password when connecting to the database at the remote server. In the new database, you could create an external login to the remote server. For simplicity in this example, the local login name and the remote user ID are both DBA:

    CREATE EXTERNLOGIN DBA
    TO RemoteSA
    REMOTE LOGIN DBA
    IDENTIFIED BY sql;
  6. Define the p_Employees proxy table:

    CREATE EXISTING TABLE p_Employees
    AT 'RemoteSA..GROUPO.Employees';
  7. Define the p_Departments proxy table:

    CREATE EXISTING TABLE p_Departments
    AT 'RemoteSA..GROUPO.Departments';
  8. Use the proxy tables in the SELECT statement to perform the join.

    SELECT GivenName, Surname, DepartmentName
    FROM p_Employees JOIN p_Departments
    ON p_Employees.DepartmentID = p_Departments.DepartmentID
    ORDER BY Surname;