Learn in your language
Skip to content
IGCSE · Cambridge (CIE) · 0265

SQL inserts, ordering and conditions

Add records and combine filters, sorting and aggregate operations while checking how a query changes a result set.

Cambridge IGCSE Computer Science 0265 · 2029 syllabus · Version 1 · 11

Mapped to the Cambridge IGCSE Computer Science 0265 syllabus for exams in 2029. These original explanations and self-checks are independent study support, not Cambridge papers, official marks or grades. Practical programming is taught with worked code and trace tasks; an executable Python workspace and timed digital-exam simulation are not yet available.

Before you begin

  • Use the 2029 syllabus for this course. Cambridge specifies Python 3.10 or higher for programming and digital exams for both components. The syllabus currently identifies this route for 2029 only; confirm later-year availability with Cambridge and your school.

Work on paper. Try each question before revealing help, and explain why your method works.

Quick readiness check

Before sql inserts, ordering and conditions, which statement is the safest starting point?

What you will learn

  • Write INSERT INTO statements with appropriate fields and values
  • Combine AND and OR conditions and sort results
  • Explain and correct the result of a SQL statement

Insert values that fit the table design

INSERT INTO adds a record to a table. Name the destination fields and provide values in the same order. Text values use quotes; numeric values use the appropriate numeric format. The record must satisfy the table's data types, keys and validation rules.

A query with multiple conditions uses AND when every condition must be true, and OR when at least one is sufficient. Use brackets where mixed conditions could be ambiguous. ORDER BY ASC sorts from low to high or A to Z; ORDER BY DESC reverses that order.

Aggregates summarise the selected records

COUNT returns the number of matching values or records; SUM totals numeric values. WHERE filters rows before the displayed aggregate is calculated. INNER JOIN combines only rows whose join condition matches in both tables.

To explain a result, trace the order: identify rows that satisfy WHERE, apply the requested aggregate or ordering, then state the columns or values returned. When correcting SQL, confirm that field names, data types, parentheses and join keys match the table structure.

Pause and explain

Which habit best checks your understanding of sql inserts, ordering and conditions?

Put the idea to work

Worked example

Insert a learner with ID 14, name 'Lan' and age 16 into Learner(LearnerID, Name, Age).

Show the worked solution
  1. Name the table and fields.
  2. Place values in matching field order.
  3. Quote text but not integer values.

Answer INSERT INTO Learner (LearnerID, Name, Age) VALUES (14, 'Lan', 16);

Try a topic test

Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.

Test this topic →

From guided practice to a new situation

Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.

1 · Guided

Write SQL to insert subject code 'CS' and title 'Computer Science' into Subject(SubjectCode, Title).

Give me a hint

Keep value order aligned with the field list.

Compare my reasoning
  1. Name the Subject table and both fields.
  2. Use the text values in single quotes.
  3. End with the values in the same order.

INSERT INTO Subject (SubjectCode, Title) VALUES ('CS', 'Computer Science');

Look for these in your work

  • Table/fields
  • Text quoted
  • Order preserved
2 · Independent

Select learners in class 'A' whose score is at least 70, or any learner with score above 90. Write a condition that makes the grouping clear.

Give me a hint

The first route requires class and score together; the second route is sufficient alone.

Compare my reasoning
  1. Group the class A and score >= 70 conditions with AND.
  2. Combine that group with score > 90 using OR.
  3. Use parentheses so the intended logic is unambiguous.

WHERE (Class = 'A' AND Score >= 70) OR Score > 90

Look for these in your work

  • First group correct
  • Alternative separated
  • Brackets clarify
3 · Transfer

A query returns COUNT(StudentID) and SUM(Score) from Results where Class='B', ordered by Score descending. Explain which rows count and what DESC does.

Give me a hint

Apply the filter before counting/summing and identify the sort order.

Compare my reasoning
  1. Only rows with Class equal to B qualify.
  2. COUNT counts StudentID values in those rows; SUM adds their Score values.
  3. DESC orders matching rows from the largest score to the smallest where row results are displayed.

The aggregates use class B rows; DESC sorts scores highest to lowest.

Look for these in your work

  • Filter applied
  • Aggregates explained
  • Sort direction stated

Common mistakes

  • Putting values in a different order from the named fields.
  • Quoting a numeric value unnecessarily or omitting quotes around text.
  • Using OR when both conditions must be true.
Recall without your notes

What can you explain now?

Which keyword sorts a query result from highest to lowest?

Compare with the explanation

DESC

ORDER BY field DESC arranges values in descending order.

After trying it yourself, choose your next review. This is your self-assessment.

Your review choice appears on Today. Sign in to sync it across devices.

Make it stick

How do INSERT, WHERE, AND/OR, ORDER BY and aggregates affect database records and query results?

If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.

Keep learning Computer Science

Course scope and assessment

All 11 syllabus topics link to 33 original lessons. Each lesson includes worked teaching, a check with explanation and guided, independent and application practice. This is mapped teaching, not evidence of exam readiness, teacher approval or a Cambridge grade. Cambridge specifies two externally assessed digital exams; StudyForA does not yet provide full timed digital-paper simulations or an executable Python 3.10+ workspace for practical programming. The currently published syllabus is for 2029; later-year coverage is not claimed.

StudyForA · Learn with understanding

Original teaching content and links to official sources. Check your exam year and qualification before using a resource.