Lesson overview
Read and write simple SQL SELECT queries using SELECT, FROM and WHERE.
Focus: SQL SELECT queries.
What you will learn
- Define the key GCSE Computer Science terms used in sql select queries.
- Explain how select works in a practical scenario.
- Compare from with an alternative or related method.
- Apply sql select queries accurately in exam-style questions.
Before you start
- Database tables and fields.
- Boolean conditions.
- Comparison operators.
SQL SELECT scenarios
Use the pupil and product tables below to choose fields, source tables and conditions.
SQL SELECT queries infographic
Explanation
SQL is a language used to query and manage relational databases.
A simple SELECT query chooses the fields to return, names the table after FROM, and can use WHERE to filter records.
String values are often written in quotes, while numeric comparisons can use operators such as =, <, >, <= and >=.
Worked examples
Applying sql select
A Products table has Name, Price and Category fields.
We need names of products in the Stationery category.
The query should only return matching records.
Answer: SELECT Name FROM Products WHERE Category = 'Stationery';
Quick checks
1. Which SQL keyword names the table to query?
- a. PRINT
- b. LOOP
- c. FROM
Reveal answer
Answer: c. Correct. FROM identifies the table used by the query.
Not quite. Focus on select in the scenario.
2. Which idea is most closely linked to sql select queries?
- a. WHERE
- b. A monitor brightness setting
- c. A random file extension
Reveal answer
Answer: a. Correct. WHERE is part of this topic.
Not quite. Choose the option that belongs to the Computer Science concept.
Practice
1. What does SELECT Name, Price do?
Reveal answer
Answer: It returns the Name and Price fields.
Marking: Credit selected fields.
2. Write a condition for age greater than 15.
Reveal answer
Answer: WHERE Age > 15
Marking: Credit correct comparison syntax.
3. What does SELECT * usually mean?
Reveal answer
Answer: Return all fields.
Marking: Credit wildcard/all columns.
4. Why use WHERE?
Reveal answer
Answer: To filter records that meet a condition.
Marking: Credit filtering.
Exam practice ladder
- Fluency: recall the key term and use it accurately.
- Application: apply the idea to the scenario rather than giving a generic definition.
- Algorithmic reasoning: show the steps, condition or variable change clearly.
- Evaluation: explain why one method, structure or control is suitable.
Answers and marking guidance
Exact answers and marking guidance are hidden under each question. For this lesson, earn marks by naming the correct Computer Science idea, applying it to the scenario and showing the logic or value change clearly.
Common mistakes
- Putting the table name straight after SELECT.
- Forgetting quotes around text values.
- Using one equals sign inconsistently with the SQL context taught.
- Returning all fields when only one is needed.
Extension
Write three SQL queries for a library table: all titles, books by one author, and books published after 2020.
Next lesson
Next, continue with SQL filtering, sorting and aggregates.
Exam-board guidance
Aplailasain is an independent learning resource and is not endorsed by any exam board.
AQA GCSE Computer Science
AQA GCSE Computer Science: this skill supports problem solving, clear algorithms and accurate programming explanations.
OCR GCSE Computer Science
OCR GCSE Computer Science: expect precise algorithm reasoning, trace work and careful use of programming vocabulary.
Pearson Edexcel GCSE Computer Science
Pearson Edexcel GCSE Computer Science: practise explaining the method as well as giving the final answer or code.
Eduqas GCSE Computer Science
Eduqas GCSE Computer Science: secure the transferable idea first, then check how your class applies it in tasks.
WJEC Wales
WJEC Wales: use accurate terminology and show enough working for the examiner to follow your logic.
CCEA
CCEA: connect the idea to your class route and use the same algorithm, programming or systems vocabulary your teacher uses.