Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Find the Employee Number, First and Last Name of Employees who are assigned to a Project, who was hired after 1/1/2003, and whose Job Designation is Manager. The two tables involved are EMPLOYEE and PROJECT.

Image Modified

Let us use Aqua Data Studio's Visual Query Builder and build the complex SQL in a few easy steps:

1. Connect to the Data Source, IBM DB2 UDB in our case.
2. Under the Data Pane, locate and select the EMPLOYEE and PROJECT tables by [Control Clicking] to multiselect them (OS X use [Command Click]).
3. Drag-and-drop the objects to the Diagram Pane.

Image Modified
4. Table Entities appear in the Diagram Pane. Click on EMPNO from the EMPLOYEE table, drag, and drop it over RESPEMP in the PROJECT table to create a JOIN.

Image Modified
5. Drag-and-drop EMPNO, FIRSTNME, and LASTNAME into the Select Deck.

Image Modified
6. From the EMPLOYEE table, drag-and-drop HIREDATE into the Where Deck. Select the [operator >] enter a value 1/1/2003.

Image Modified

Image Modified
7. Next drag-and-drop JOB from the EMPLOYEE table into the Where Deck. Select the [operator =] and enter the title MANAGER.

Image Modified

Image Modified
8. Navigate to the SQL Pane and you can see that a complete SQL statement based on your criteria is automatically generated. You should see a SELECT statement that takes into account each of the items you dragged into place. You cannot type in this area. The SQL statement in the SQL Pane should resemble:

No Format
select
	"EMPLOYEE"."EMPNO",
	"EMPLOYEE"."FIRSTNME",
	"EMPLOYEE"."LASTNAME" 
from
	"ADMIN"."EMPLOYEE" "EMPLOYEE" 
		inner join "ADMIN"."PROJECT" "PROJECT" 
		on "EMPLOYEE"."EMPNO" = "PROJECT"."RESPEMP" 
where
	("EMPLOYEE"."HIREDATE" > '1/1/2003') AND
	("EMPLOYEE"."JOB" = 'MANAGER')

Image Modified

Press [Ctrl + E] ([Cmd + E] on OS X) or click on the [Execute button] in the Query Builder Toolbar to view the result of the generated SQL Query.

Image Modified

Info

These basic actions are used throughout the Query Builder. Drag your column either from the Data Pane or Table Entity into a Deck, or, for JOINs, drag your column from one Table Entity onto a column in another Table Entity.

...