Skip to content
IGCSE·Tuition

Tools

Read-only SQL practice lab

A query can look fine and still return the wrong rows, usually because of one condition grouped the wrong way.

On this page
  1. How do you use it?
  2. How do you read the result?
  3. Example walk-through
  4. What are the assumptions and limits?
  5. Which lessons explain the result?

Everything you enter stays on this device. Nothing is sent to us.

This lab lets you practise SELECT queries on one small fictional table called Books. It has twelve rows and the columns BookID, Title, Genre, Pages, Price and Stock.

Only read-only queries are accepted, so you can experiment freely, and each result comes with a step-by-step account of how it was worked out.

How do you use it?

  1. Pick one of the eight exercises. Each one is a plain-English task, for example “Show Title and Price of all Fantasy books.”
  2. Write your query in the text box. Some exercises start with a query that is almost right. Predict what it will return first.
  3. Press Run query. Reset returns the lab to its starting state.
  4. Read How it was worked out, then compare Your result with Expected result.

Supported: SELECT with columns, * or COUNT, SUM, AVG, MIN and MAX; FROM Books; WHERE with =, <>, <, >, <=, >=, AND, OR, NOT, LIKE, BETWEEN and IN; ORDER BY; LIMIT. Text values go in single quotes.

How do you read the result?

The steps section follows the real order of thought: FROM Books starts with all 12 rows, WHERE keeps only rows where the condition is true and says how many are left, ORDER BY sorts them, LIMIT keeps the first few, and SELECT chooses which columns to show.

Then you see your table next to the expected table, with a message on whether they match and whether the order also matters for this exercise.

Example walk-through

Choose the exercise “Show the Title of Mystery or Science books that are out of stock (Stock is 0)”. The starting query is:

SELECT Title FROM Books WHERE Genre = ‘Mystery’ OR Genre = ‘Science’ AND Stock = 0

Run it and you get three rows: Silent Harbour, Paper Lanterns and Night Train. The expected result has two rows. Why?

AND is applied before OR. So the query means “Mystery, or (Science and out of stock)”. Every Mystery book passes, stocked or not. No Science book has Stock 0, so the second part adds nothing.

Fix it with brackets: WHERE (Genre = ‘Mystery’ OR Genre = ‘Science’) AND Stock = 0. Now the genre test is done first, then the stock test. The result is Silent Harbour and Night Train, and it matches.

Try a second one: “Count the books that cost less than 20.” SELECT COUNT(*) FROM Books WHERE Price < 20 returns 5, from the prices 18.5, 14, 19.9, 16.5 and 9.9.

Then test the guard: type DROP TABLE Books and read the rejection.

What are the assumptions and limits?

  • The data is fictional and fixed. No personal data is used and no outside database can be connected.
  • Only one read-only SELECT is run. Extra statements, comments and file functions are rejected.
  • It is a small evaluator, not a full database engine. Joins, GROUP BY and subqueries are not available, and mixing columns with aggregate functions is refused.
  • Text comparisons need quotes. A number compared with text gives a clear error.
  • It is for original practice. It does not mark assessed work or use your own data.

Which lessons explain the result?

Start with writing a simple SELECT filter. The bracket issue in the example is the subject of combining conditions with the correct Boolean grouping. When you get zero rows, read explaining why a query returns no rows.

For mixed questions, try databases and query reasoning practice, and see the whole topic in databases and query reasoning. If you study the practical ICT route, applying multiple query criteria correctly covers the same grouping idea in database software.

Want a teacher to check your queries with you? See online one-to-one Computer Science tuition or ICT tuition. More tools are in the learning tools directory.

Questions people ask

Can this lab change or damage any data?

No. It accepts one SELECT statement at a time on a small fictional Books table held inside the page. Words such as DROP, UPDATE, DELETE and INSERT are rejected before anything runs, as are multiple statements and file functions. Nothing is stored, and the data resets every time.

Why was my query rejected?

The message tells you the reason. Common ones are starting with something other than SELECT, using a second statement after a semicolon, including a comment, or naming a column that does not exist. The columns are BookID, Title, Genre, Pages, Price and Stock, and the only table is Books.

Does it support joins and GROUP BY?

No. The lab has its own small evaluator that covers SELECT with columns, * or COUNT, SUM, AVG, MIN and MAX, FROM Books, WHERE, ORDER BY and LIMIT. Joins, GROUP BY and subqueries are outside it. Check your current syllabus for what your exam year expects.

What does Expected result mean?

Each exercise has a reference query that gives the target rows. The tool compares your rows with them, and for some exercises the row order counts too. If they differ, compare the two tables and check the WHERE condition, the columns and ORDER BY.

Sources

  1. Cambridge IGCSE Computer Science 0478 syllabus page

Updated:

Your next step

If your queries run but return the wrong rows, a one-to-one teacher can go through your WHERE conditions with you and show where the grouping changes the meaning.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80. Other fees, schedules and ongoing arrangements are confirmed directly with your teacher after the trial class.

9,000+ students helped through our service