Create a self-join in a query automatically (ADP)

Microsoft Office Access 2003

Show All Show All

Create a self-join in a query automatically (ADP)

If a table has a reflexive relationship in the database, you can join it to itself automatically.

  1. In the Database window, click Queries Button image under Objects, click the query you want to open, and then click Design on the database window toolbar.
  2. Add to the Diagram pane the table, view, or function you want to work with.

    ShowHow?

    When you create a query, you are retrieving data from a table, view, or function. To work with any of these objects in your query, you add them to the Diagram pane.

    ShowAdd a table, view, or user-defined function to the query

    1. In the Database window, click Queries Button image under Objects, click the query you want to open, and then click Design on the database window toolbar.
    2. In the Diagram pane, right-click the background and choose Add Table from the shortcut menu.
    3. In the Add Table dialog box, select the Tables, Views, or Functions tab.
    4. In the list of items, double-click each item you want to add.
    5. When you finish adding items, click Close.

    The Query Designer updates the Diagram pane, Grid pane, and SQL pane accordingly.

    Alternatively, you can drag objects onto the Diagram pane. You can drag a table, view, or inline function from the database window.

    You can also drag columns or tables from the Database Designer or paste them from the Clipboard.

    Tables and views are automatically added to the query when you reference them in the statement in the SQL pane.

    The Query Designer will not display data columns for an table, view, or inline function if you do not have sufficient access rights. In such cases, only a title bar and the * (All Columns) check box are displayed for the table, view, or inline function.

    ShowAdd an existing query to a new query

    1. If necessary, click SQL Button image to show the SQL pane.
    2. In the SQL pane, type a right and left parentheses () after the word FROM.
    3. Open the Query designer for the existing query . (You now have two Query Designers open.)
    4. Display the SQL pane for the inner query – the existing query you are including in the new, outer query.
    5. Select all the text in the SQL pane, and copy it to the Clipboard.
    6. Click in the SQL pane of the new query, situate the cursor between the parentheses you added, and paste the contents of the Clipboard.
    7. Still in the SQL pane, add an alias after the right parenthesis. For more information on SQL aliases and subqueries, see the Microsoft SQL Server documentation.
  3. Add the same table, view, or function again, so that the Diagram pane shows the same table, view, or function twice within the Diagram pane.
    The Query Designer assigns an alias to the second instance by adding a sequential number to the table, view, or function name. In addition, the Query Designer creates a join line between the two rectangles representing the two different ways the table, view, or function participates in the query.