Menu

SQL stands for Structured Query Language. It is the language used to search a database. A search written in SQL is called a query. A query only retrieves data; it does not change the data stored in the database.

What a query states

A query states which fields to show, which table to search and which records to include. These three parts are written as clauses in a fixed order.

ClauseWhat it givesOrder
SELECTThe fields to show1st
FROMThe table to search2nd
WHEREThe condition that records must meet to be included3rd

A worked example

Imagine a table called TblVolunteers that stores the people helping out at a community garden. It has fields including volunteerName and hoursWorked. To show the names of the volunteers who have worked more than 12 hours, you list volunteerName after SELECT, name TblVolunteers after FROM, and put the condition hoursWorked > 12 after WHERE, in that order:

SELECT volunteerName FROM TblVolunteers WHERE hoursWorked > 12

The result lists only the names of volunteers whose recorded hours pass the test. Every value already stored in the table, including the hours that failed the condition, stays exactly as it was, because the query reads the records without altering them.

A query needs only SELECT, FROM and WHERE. Commands such as INSERT, UPDATE and DELETE would add, change or remove records, so they are not used to search.

Practise this