For a single relation query, we can enter either constants or example elements in the columns of the template of that relation. An example element (domain variable) is specified as an underscore character, as in _x and constant appear without any qualification.
Query 1: Find the name, address of employees who work for department number 1
| EMPLOYEE | SSN | Name | Bdate | Address | Salary | DeptId |
| P._x | P._y | 1 |
For the above query, the system will look in to the relation EMPLOYEE and look for tuples that have 1 as the value for DeptId column. For each such tuple, the value of Name attribute is assigned to variable x, the value of Address attribute is assigned to variable y. Because the command P. appear before variables x, y , the values of these variables will
be printed as the results of query. If a variable appears only once in a query, it may be omitted. Therefore, the previous query could be rewritten as
| EMPLOYEE | SSN | Name | Bdate | Address | Salary | DeptId |
| P. | P. | 1 |
Query 2: Find employee’s name of all employees who work for department number 1
QBE eliminate duplication automatically. Thus, in order to avoid duplicate elimination, we insert command ALL. after the P. command.
| EMPLOYEE | SSN | Name | Bdate | Address | Salary | DeptId |
| P.ALL. | 1 |
Query 3: Find the employees whose salary is greater than 30.000
For this query, we want to display the whole tuple if the value in the Salary is > 30.000. To do so, we place the P. command in the column headed by the relation name.
| EMPLOYEE | SSN | Name | Bdate | Address | Salary | DeptId |
| P. | > 30.000 |
As we can see, a query in QBE can use arithmetic comparison. However, the comparisons can only involve only one arithmetic expression on the right hand side of the operation. QBE supports all operation such as > , <, = , ≥, ≤, ( different).
Query 4: Find the name of dependents of all employees except employee number 123456674
| EMP-DEPENDENT | ESSN | Dependent-Name | Bdate | Relationship |
|
|
P. |
Query 5a: Find the employee’s number of employees who join in project number 3 or in project number 4
| JOIN | ESSN | PCode | StartDate |
| P._x | 3 | ||
| P._y | 4 |
Query 5b: Find the employee’s number of employees who take part in both project number 3 and project number 4
| JOIN | ESSN | PCode | StartDate |
| P._x | 3 | ||
| _x | 4 |
The primary pupose of variables in QBE is to force values of certain tuples to have the same values on certain columns. For the above query, QBE will find all pairs of tuples that have the same values of ESSN attribute but the value of PCode in one tuple is 3 and the value of this attribute in other tuple is 4.
Query 5c: Find the employee’s number of employees who join in project number 3 but donot take part in project number 4
| JOIN | ESSN | PCode | StartDate |
| P._x | 3 | ||
| _x |
|
Query 6: Find the employee’s number of employees who join in the same projects with employee number 123456674
| JOIN | ESSN | PCode | StartDate |
| 123456674 | _x | ||
| P._y | _x |






