Study resource
Structured Query Language (SQL) study guide
Study Structured Query Language (SQL) with curriculum-aligned Study Guide resources, practice links, and exam-focused support.
At a glance
study guide
Resource type
Topic
Structured Query Language (SQL)
Study guide overview
Applying SQL Across Relational Database Tables
Use this guide to reason from a database task to an appropriate SQL statement, particularly when data must be retrieved from multiple tables.
Start by identifying the required operation
Read the task and decide whether it asks you to retrieve, insert, update or delete data, or to define a table. The verb in the task should lead to the main SQL command:
- retrieve data:
SELECT - add data:
INSERT INTO - change existing data:
UPDATE - remove data:
DELETE FROM - define a table:
CREATE TABLE
This first decision prevents using a command that performs a different operation.
Build the statement from the data requirement
For a retrieval task, identify the columns that must be displayed, the table or tables containing them, and any condition that limits the result. For example, if the required output contains a student's name and a course name stored in different tables, a query must select both columns and use a relationship between the tables:
sql SELECT Student.StudentName, Course.CourseName FROM Student JOIN Course ON Student.CourseID = Course.CourseID;The
SELECTlist controls which data is retrieved.FROMandJOINidentify the tables. TheONexpression explains which values are used to match rows. If a condition is also required, add aWHEREclause, such as:sql SELECT Student.StudentName, Course.CourseName FROM Student JOIN Course ON Student.CourseID = Course.CourseID WHERE Student.YearGroup = 12;Here, the join combines information from two tables, while
WHERErestricts the result to students in the specified year group. Keeping the matching condition and the filtering condition distinct makes the reasoning clearer.Reason about changes carefully
For
INSERT INTO, check that every supplied value corresponds to the intended column. ForUPDATE, identify the exact rows to change and place that selection inWHERE. ForDELETE FROM, use the same careful approach because the command removes rows rather than merely displaying or changing them.sql UPDATE Student SET YearGroup = 13 WHERE StudentID = 101;The statement changes the value for the row identified by
StudentID. A different condition would change a different set of rows, so an exam answer should explain why its condition selects the intended data.Defining a table
When asked to define a table, provide
CREATE TABLE, a table name, column names and data types. The definition should be read as a description of the structure that later SQL statements will use.sql CREATE TABLE Course ( CourseID INTEGER, CourseName VARCHAR(60) );The later
SELECT,INSERT,UPDATEandDELETEstatements must refer to names that were defined consistently. Check spelling, table qualification and the correspondence between columns and values.Self-check before submitting an answer
Ask yourself:
- Does the main command match the requested operation?
- Are the table and column names consistent throughout?
- If multiple tables are used, is the matching relationship explicitly stated?
- If only selected rows should be changed or removed, is there an appropriate
WHEREcondition? - In an insertion, do the values align with the listed columns?
- In a table definition, are the table name, columns and data types present?
A strong answer is not just syntactically plausible: each clause should have a clear role connected to the task.
- retrieve data:
Ready to practise?
Choose your next step
Use the study guide for understanding, then switch into an active revision mode.
Related topics
