Retrieving specific data using standard SQL syntax.
Open the blank Google Doc I have shared with you. Review the screenshot of the Python code below. There are 4 errors hidden inside (2 Easy, 2 Hard).
Task: Fix the code and paste your corrected, working version into your Google Doc.
| Difficulty | Error Type | Location | Description |
|---|---|---|---|
| Easy | Indentation | Line 5 | Block Error: The print statement must be indented to sit inside the if block. |
| Easy | Syntax | Line 6 | Missing Colon: The else statement is missing the : at the end. |
| Hard | Concept / Logic | Line 4 | Assignment vs Comparison: A single = assigns a value. To check equality, you must use ==. |
| Hard | Concept / Maths | Line 3 | Flat Rate vs Percentage: The code just subtracts 20. It needs to calculate the percentage: original_price - (original_price * (discount_percent / 100)). |
To write standard SQL statements to retrieve specific data from a database table.
A digital filing system that stores lots of information so it's easy to search and manage.
A grid of rows and columns that stores data about one specific topic (like a register).
One complete horizontal row. It holds all the information about a single person or item.
A single vertical column or category of data (e.g., a column just for 'Surnames').
A Query is a question we ask the database to find data. We write these using Structured Query Language.
SELECT Name
FROM tblStudents
The strict spelling and grammar rules required so the computer understands your code.
To pull specific data from a database, we use SQL. Look at the tblStudents table below as our example data.
| StudentID | FirstName | Surname | Age | Subject |
|---|---|---|---|---|
| 1 | John | Smith | 15 | Computing |
| 2 | Sue | Jones | 16 | History |
SELECT chooses the columns. FROM chooses the table. The asterisk * is our wildcard for "all fields".
Check for Understanding
I want to write a query that pulls ONLY the Surnames from this table. Write the two lines of SQL required to do this.
(Answer: SELECT Surname / FROM tblStudents)
chunk1.html file in your browser.The WHERE clause adds a filter/condition to our query to pull specific records rather than all of them.
CRITICAL EXAM TRAPS:
== to check if something matched. In SQL, we only use a single = sign.'Sci-Fi'). Numbers do not need quotes.I have run this query, but it caused a syntax error. Write the correct, fixed query on your Mini Whiteboards and hold them up.
chunk2.html file in your browser.To finish the lesson, you will complete a short multiple-choice and short-answer quiz to check your understanding of today's key concepts: Databases, Tables, Records, Fields, and the SELECT, FROM, and WHERE clauses.
Task: Complete the final Google Form quiz to evaluate your learning.
Open in Google Forms