0% found this document useful (0 votes)
10 views11 pages

List Full Details of All Staff

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views11 pages

List Full Details of All Staff

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

1.

Retrieve all rows

List full details of all staff

SELECT staffNo, fName, lName, position, sex, DOB, salary, branchNo

FROM Staff;

SELECT *
FROM Staff;

The result table in either case is shown in Table 5.1.


Table 5.1 Result table for Example 5.1.

Produce a list of salaries for all staff, showing only the staff number, the first and last
names, and the salary details.

SELECT staffNo, fName, lName, salary


FROM Staff;
List the property numbers of all properties that have been viewed.
SELECT propertyNo
FROM Viewing;

SELECT DISTINCT propertyNo


FROM Viewing;

Example 5.4 Calculated fields


Produce a list of monthly salaries for all staff, showing the staff number, the first and last
names, and the salary details.

SELECT staffNo, fName, lName, salary/12


FROM Staff;
Example 5.5 Comparison search condition

List all staff with a salary greater than £10,000.


SELECT staffNo, fName, lName, position, salary
FROM Staff
WHERE salary  10000;

In SQL, the following simple comparison operators are available:


= equals
  is not equal to (ISO standard) ! = is not equal to (allowed in some dialects)
 is less than  = is less than or equal to
 is greater than  = is greater than or equal to

Example 5.6 Compound comparison search condition


List the addresses of all branch offices in London or Glasgow.
SELECT *
FROM Branch
WHERE city = ‘London’ OR city = ‘Glasgow’;

Example 5.7 Range search condition (BETWEEN/NOT BETWEEN

List all staff with a salary between £20,000 and £30,000.

SELECT staffNo, fName, lName, position, salary


FROM Staff
WHERE salary BETWEEN 20000 AND 30000;
Example 5.9 Pattern match search condition (LIKE/NOT LIKE)

You might also like