OCR A-Level Computer Science H446
Processors: Structure, Performance and Types
Input, Output and Storage
Systems Software
Applications Generation
Software Development
Types of Programming Language
Exchanging Data
Networks
Web Technologies
Data Types and Number Representation
Data Structures
Boolean Algebra
Legal, Moral, Cultural and Ethical Issues
Elements of Computational Thinking
Problem Solving and Programming
Algorithms
Exchanging Data
SQL: Interpreting and Modifying Queries
- 3 things to know
- Component 01
Overview
Recall questions on SQL SELECT, FROM and WHERE, the wildcard and LIKE, AND and OR, JOIN, nested SELECT, INSERT INTO, DELETE and DROP, and interpreting, writing and correcting queries.
What you need to know
Answer each one before you reveal it.
Explain step by step what this query does: SELECT Title FROM Book WHERE AuthorID = (SELECT AuthorID FROM Author WHERE Surname = 'Pratchett').
Write a query returning the title and author of every book in a Book table whose title begins with 'The'.
Questions from this subtopic
Each one with the model answer underneath.
- 1
What is SQL used for?
Model answer
SQL, Structured Query Language, is the standard language for interrogating and manipulating data in a relational database. It is used to retrieve records matching stated conditions, to add new records, to remove records, and to change the structure of the database itself, without the user needing to know how the data is physically stored.
- 2
What do the SELECT, FROM and WHERE parts of a query each specify?
Model answer
SELECT lists the fields to be returned. FROM names the table or tables the data comes from. WHERE gives the condition a record must satisfy to be included, so it filters which records are returned. SELECT chooses the columns; WHERE chooses the rows.
- 3
Explain what this query returns: SELECT Surname, Form FROM Student WHERE YearGroup = 12
Model answer
It returns the surname and form of every student in the Student table whose YearGroup field holds the value 12. Only those two fields are shown, and students in any other year group are excluded.
- 4
What does the * mean in SELECT * FROM Book WHERE Genre = 'Crime'?
Model answer
The asterisk is a wildcard standing for all fields, so the query returns every field of every record in the Book table whose Genre is Crime, rather than a named subset of columns.
- 5
Explain what LIKE does, and what the % wildcard matches.
Model answer
LIKE compares a text field against a pattern rather than requiring an exact match, and % is a wildcard standing for any sequence of characters, including none at all. So Surname LIKE 'M%' matches any surname beginning with M, Surname LIKE '%son' matches any ending in son, and Title LIKE '%dragon%' matches any title with dragon anywhere in it.
- 6
Write a query returning the title and author of every book in a Book table whose title begins with 'The'.
Model answer
SELECT Title, Author FROM Book WHERE Title LIKE 'The%'
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Exchanging Data, on a schedule.
Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.
Or £46 a year, about £3.83 a month. Cancel anytime.