Creating a FULLSELECT (UNION) Statement

Use SQL Query Builder to create a FULLSELECT UNION statement, which combines the results set for two tables.

Prerequisites 

Connect to the data source through a connection profile.

Note: Some syntactic variations might exist between your database and the SQL syntax that SQL Query Builder supports; consequently, some SQL Query Builder features might not work with your database.
  1. Open a new or an existing SQL file, and be sure to select the connection profile Type, Name, and Database.
  2. In an appropriate place in the editor window, right-click and select Edit in SQL Query Builder.
  3. Righ-click SELECT Statement, and select Convert to FULLSELECT (UNION).
  4. Add one or more tables to the statement.
    1. Right-click in the Tables pane and select Add Table.
    2. (Optional) Indicate a Table alias.

      You might want to use a table alias to make the table name more readable or shorten it for display/output.

  5. Define the SELECT statements.
    1. In Outline view, expand the SELECT Statement and Union trees.
    2. Click the first SELECT, and then create the SELECT statement.
    3. Click the second SELECT, and then create the SELECT statement.

      All selected columns need to be of the same data type.

    You can nest a FULLSELECT UNION statement under a SELECT statement.

  6. (Optional) Click SELECT Statement to define any other SELECT Statement options, such as operator or sort type.

    UNION only selects distinct values while UNION ALL selects all values.

    1. Next to the statement type, select UNION ALL to change the Operator from the default UNION.
    2. Change the sort type or sort order.
  7. (Optional) To run the SQL code, in the SQL Source pane, right-click and select Run SQL.

    View the results in the SQL Results tab.

  8. Click OK to exit SQL Query Builder and to return to the SQL File Editor, where the SQL code displays in the editor window.

    Clicking Cancel results in no changes to the SQL code in the SQL File Editor. You lose any changes you made in SQL Query Builder.

Related tasks
Creating a SELECT Statement
Creating a WITH Statement
Creating Joins