A-level Computing/AQA/Problem Solving, Programming, Operating Systems, Databases and Networking/Databases/SQL

UNIT 3 - ⇑ Databases ⇑

Normalisation SQL SELECT
Category:Book:A-level Computing#AQA/Problem%20Solving,%20Programming,%20Operating%20Systems,%20Databases%20and%20Networking/Databases/SQL

Structured Query Language (SQL) is used to perform function on a database. There are four main functions that you should be familiar with: SELECT, INSERT, UPDATE, DELETE

To help us understand how these things work we are going to use a test data set. Databases are used in all areas of the computer industry, but for the moment we are going to use a dataset that keeps track of crooks in England, noting, names, gender, date of birth, towns and numbers of scars. Take a look at the crooks data table below:

IDnamegenderDoBtownnumScars
1Geoffmale12/05/1982Hull0
2Janefemale05/08/1956York1
3Keithmale07/02/1999Snape6
4Olivermale22/08/1976Blaxhall2
5Kellyfemale11/11/1911East Ham10
6Mareafemale14/07/1940Wythenshawe6

To select all the items from this table we can use:

SELECT * FROM crooks

This would display all the results. But what if we just want to display the names and number of scars of the female crooks?

SELECT name, numScars FROM crooks
WHERE gender = 'female'

The result of this query would be:

namenumScars
Jane1
Kelly10
Marea6
Questions

Write an SQL statement that selects the names and dates of birth of male crooks with less than 3 scars.

Answer:


SELECT name, DoB FROM crooks
WHERE gender = 'male'
AND numScars < 3
Extension: Practice SQL

You can practice your SQL skills using Access, MySQL (as part of XAMPP), MSSQL, SQLite etc. If you don't have this software easily available you might want to take a look at the SQLZoo site, which allows you to hone your skills in an online environment where you don't have to worry about accidentally deleting all your records! For the exam and probably for your projects you need to be very good at SQL, so get practicing.


AQA Teacher Resources: Database querying a database using SQL
Category:Book:A-level Computing#AQA/Problem%20Solving,%20Programming,%20Operating%20Systems,%20Databases%20and%20Networking/Databases/SQL%20
Category:Book:A-level Computing