Skip to main content

SELECT Statement: Where Examples

SELECT command Returned result

SELECT *

FROM employee

WHERE salary >10000;

All data for employees with a salary greater than 10,000

SELECT forename, surname

FROM employee

WHERE gender = 'M'

AND salary < 15000;

The names of those male employees who earn less than 15,000

SELECT forename, surname

FROM employee

WHERE date_of_birth >= '01-Jan-1966'

AND date_of_birth <= '31-Dec-1966';

The names of all employees born in the year 1966

Note the structure of a date

SELECT forename, surname

FROM employee

WHERE section_name = 'Pensions'

AND (surname = 'Jones'

OR surname = 'Wong')

AND gender = 'F';

Note the use of brackets in this example. Without them the wrong rows would be returned as AND conditions are evaluated before the OR condition

The names of all female employees who work in the pensions section and have a surname of either Jones or Wong

Remember string selections are case sensitive. This WHERE clause would not find rows with surnames of JONES and WONG

SELECT student_number, title, forename, surname

FROM student

WHERE course_number <> 'CN0100';

All students who are not on the course whose number is CN0100

SELECT student_number, title, forename, surname

FROM student

WHERE NOT course_number = 'CN0100';

All students who are not on the course whose number is CN0100

Yes, this is the same as the query above. SQL commands can be written in different ways and still return the same result



Next: SELECT Statement: the ORDER BY clause