Creating an SQL string using QBE:

1.   Select Query by Example Interface from the Option menu.  

2.   The Create QBE Wizard Introduction dialog box appears.  

3.   Click the Next button. The Choose Table(s)/Column(s) window appears.   

4.   Choose one table/view or multiple tables/views from the Table Name drop down list. When specifying a table or view, the columns contained in the selected table(s)/view(s) appear on the left side of the window.

5.   Double-clicking a column name selects the column. Alternatively, click once on a column then click the Add button. The Add all button adds all columns to the replication. All the selected columns appear in the list box to the right. Likewise, columns are removed from the replication by double-clicking the column name or selecting the column and clicking the Remove button.

NOTE     To select multiple columns press and hold the Ctrl key and select the column with the mouse. 

6.   Click the Next button. The Adjust Selected Column's Order dialog box appears.

7.   Enabling the Use wildcard setting is helpful for fetching all the table's records using wildcards. Optionally click the Use wildcard checkbox to enable this feature.

8.   Select a Remove duplicate record option. The Default (ALL) radio button fetches all records. In other words, duplicate records are not exclused from the results. The Distinct radio button option removes duplicate data records from the results of a query (i.e., only unique data record are included in the results).   

9.   To expand the table to view to include all of the available columns double-click the table or click the expanding icon () at the side of table name.

10.   Select a column from the column list. The selected column highlights. Right-click the column to set an aggregate function or remove it from the projected column using a pop-up menu. QBE supports five aggregate functions: AVG, COUNT, MAX, MIN, and SUM.

11.   QBE can apply UDF functions into projected columns. Click the Add UDF button and the following window appears. Column Name and Column Type fields show the selected column's name and type. Select a UDF from the Match Function Name drop down menu, the selected UDF appears in the Description area. To help illustrate the UDF, examples appear in the Example area. Click the OK button.

12.   Click the Modify UDF/Remove UDF buttons to modify or remove the selected UDF function.

13.   Click the Setting button. The Projected Column Operation window appears as shown below. You can choose one operator from the Operator drop down list. Choose one column from the Table(alias).Column drop down list. Click the Add button. The operation appears in the Preview area below the window. Use the Up, Down, and Remove buttons to adjust the selected column's order. Click the OK button.

 

14.   Double-click the Alias Name field for a column to specify an alias name.

15.   Select a column from the Table/Column field using the mouse. The selected columns highlight. Click the Up, Down, or Remove buttons to adjust or drop the selected column.

16.   Click the Next button. The Where Clause window appears.

17.   Select a column from the Table(alias).Column(alias) drop down list on the left.

18.   Select an operator from the Operator drop down list. QBE supports following operators: =, >, <, >=, <=, <>, +, -, *, /, ||, between, is null/is not null, in/not in, like/not like, match/not match, and contain/not contain.

19.   Enter a value in the Table(alias).Column(alias) field on the right or select a column from the drop down list.

20.   Click the Add button. The where condition appears in the panel below the window.

NOTE   If some selected tables have a PK/FK relationship, QBE makes the default PK/FK relation a where condition.      

21.   Optionally, add a UDF function by clicking the Import button () on the right of the Table(alias).Column(alias) field to add a UDF function. Click the Export button () to cancel the selected UDF function.

22.   The QBE interface supports ten functions:

23.          Click the Next button. The Group by Clause window appears.

24.  Select columns to use Group by Clause. A group is a set of rows that having the same values of group by columns. For each group, a single row of aggregate results is generated.

25.   Click the Next button. The having clause window appears. Please refer to steps 12 through 16 for details.

26.   Click the Next button when you are satisfied with the clauses. The Order by Clause window appears.

27.   Select the sort order for the columns using the Order by Clause dialog box. The order by clause can sort query results by the values contained in selected columns.

28.   Click the Next button. The Building SQL Review dialog box appears. QBE make a SQL script automatically, you can modify it manually. For the final SQL, you can save an external file, create it as stored command, create it as view, or preview the execution SQL result.

29.   To save the query, click the Save button. The Save dialog box appears.

30.   To save the query as a stored command, click the Save as stored command button. The Input stored command name dialog box appears.

31.   To preview the query, click the Preview button. The Preview QBE Result dialog box appears.

32.   To create a view on the query, click the Create as view button. The Input View Name dialog box appears.

33.   Click Previous to return to prior windows or click the Close button when you are satisfied with the QBE.



Related topic:

Query by example (QBE)