ImplementationSELECT…FROM… WHERE… clause

Structured Query Language is used to allow database developers to generate queries and interrogate the data held in a database. SELECT, FROM, WHERE, AND and OR are key areas of SQL.

Part ofComputing ScienceDatabase design and development

SELECT…FROM… WHERE… clause

To go a step further, the WHERE clause can be used. The WHERE clause will only return records that meet a specific condition.

SELECT PupilID, Surname, Class FROM Pupil
WHERE Class = ‘1T1’;

This would return:

PupilIDSurnameClass
0001Singh1T1
0004McNamee1T1
0007McNamee1T1
0008Matazinadze1T1
PupilID0001
SurnameSingh
Class1T1
PupilID0004
SurnameMcNamee
Class1T1
PupilID0007
SurnameMcNamee
Class1T1
PupilID0008
SurnameMatazinadze
Class1T1

The WHERE clause has been used to ensure that the only records returned are those that have the value ‘1T1’ in the class column/field.