How to use the Model Area
Note: If no table columns are selected, then all columns will be included in the query.
Build a Query
Follow this procedure to get started using the Query Builder.
To build a query
- Drag-and-drop Tables, Views, or Synonyms from the Schema Browser, Project Manager, Object Palette, or the Object Search window to the Query Builder workspace tab.
Click in the checkbox by a column to add it or remove it from the active query's SELECT clause.
- Drag-and-drop columns from one table to another to create joins between the tables.
- Add any WHERE, GROUP BY, HAVING, or ORDER BY clauses by right-clicking on the column and selecting Include in n clause. Right-click and adjust properties for clauses where necessary.
To create a new clause, drag-and-drop columns from a table to WHERE, GROUP BY, HAVING or ORDER BY in the Query Browser tree node.
- Click on the toolbar to save the model to disk.
- Click the Generated Query tab to view or edit the generated query.
- If you update the diagram and the SQL code is not synchronized, click in the Generated Query toolbar to update the code.
- If you update the code, click in the Generated Query toolbar to updated the diagram.
See also Create a Subquery
Create a Sub-Query
You can easily create a subquery or nested subquery. Subqueries can be created from the FROM clause or the WHERE clause.
Columns must be dragged directly from the table area to be placed in subqueries, or from the current statement.
After initiating the subquery using one of the methods below, create the subquery as you would a normal query.
To create a subquery in the WHERE clause
- Drag a column into the WHERE node.
In the Condition dialog, use the simple or complex mode.
If you click Nested Subquery, the new subquery is created in the workspace.
To create an EXISTS subquery
- Right-click the WHERE clause in the tree view.
- Select Add EXISTS Subquery or Add NOT EXISTS Subquery.
To create a subquery in the FROM node
- Right-click the FROM clause in the tree view.
- Select Add | New Named Subquery (or New Inline View).
Populate the Where Clause
Work with Code > Work with the Query Builder > Populate the Where Clause
There are two ways to populate the WHERE clause in SQL generated by the Query Builder: as an individual WHERE, or as a global WHERE.
To populate the where clause
- Do one of the following:
- Right-click on the column under the SELECT node and select Include in Where Clause.
- Drag a column from the select node to the WHERE node.
Add conditions and select or clear any outer joins you want to apply.
Note: To build a more advanced query, click the Expert tab and enter your code by typing it in the top box or double clicking on functions and data fields to enter them.
Repeat until all conditions are added.
Note: When you add multiple columns to a WHERE clause, they are automatically placed
If a condition should be an OR condition, rather than an AND, right-click on it and select OR.
To create a global WHERE clause
- Right-click in the Table Model area.
- Select SQL | Global Where Clauses.
- Click .
- Enter or build your condition.
- Click OK to close the definition window.
- Click OK.
To construct the following query:
SELECT DEPT.DEPTNO, DEPT.DNAME, DEPT.LOC
WHERE (((UPPER (RTRIM (DNAME)) = 'SALES') AND (DEPT.DEPTNO < 40)) AND ((DEPT.LOC = 'CHICAGO')OR ((DEPT.LOC IS NULL = '')))
Do the following:
- Open the Query Builder.
- In the Object Palette, select the Scott schema and double-click the DEPT table to add it to the model.
- Right-click DEPT and choose Select All.
- Drag the DEPTNO column to the WHERE node.
- Select < in the operator box, click Constant, and enter 40 in the condition box.
- Click OK.
- Drag the LOC column to the WHERE node.
- In the WHERE definition dialog, click the Expert tab. Click OK to confirm.
- Double-click IS NULL in the SQL Operators area and then click OK.
- Drag the DEPTNO above LOC in the tree view.
- Right-click the LOC column and select OR.
- Right-click on OR | LOC and select Properties. Select = in the operator box, click Constant, and enter CHICAGO in the condition box.
- Click OK.
- In the table model area (the area around the table images), right-click and choose SQL | Global Where. Click .
- In the top edit box, enter (UPPER (RTRIM (DNAME))) = 'SALES'.
- Click OK and then click OK again.
View the generated query. It should display as described above.