Skip to content
SPM Tuition
Free tool · Computer Science

SQL reasoning sandbox

Your query runs but you cannot say why it returns those rows.

This tool lets you type a SELECT query against a small fictional school-club database and shows the result together with what each clause did. It is for students who can write a query that runs but cannot explain the rows it returns.

Everything you enter stays on this device.

How do I use it?

  1. Pick an example from the list, or type your own SELECT query.
  2. Press “Run query”.
  3. Read the result table, then the numbered stages that show how many rows went in and out of each clause.
  4. Change one clause and run again to see its effect.

How does it work?

The tool reads your text with a small parser that accepts SELECT, FROM, JOIN … ON, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT, and the functions COUNT, SUM, AVG, MIN and MAX. Anything else is rejected with a clear message.

Stages follow the order the rules are applied: FROM and JOIN build the rows, WHERE filters them, GROUP BY collapses them into groups, HAVING filters groups, then ORDER BY and LIMIT shape the output.

NULL means no value. A comparison with NULL is never true, and COUNT(column), SUM and AVG skip NULL. The Members table has one NULL on purpose, and the Clubs table has a club with no members, so empty groups appear in the practice.

A short worked example

The Scores table holds A with 40, B with 70 and C with 70. The query SELECT name FROM Scores WHERE score >= 70 ORDER BY name returns B then C.

SELECT COUNT(*) FROM Scores returns 3, because it counts rows. SELECT AVG(score) FROM Scores returns 60, since (40 + 70 + 70) ÷ 3 = 60.

Change the condition to score > 100. No row matches, so the result is empty, while COUNT(*) on the same filter returns 0.

What are its limits?

The database is fictional and small. The tool is not a full SQL engine and does not show how any particular database system behaves. It stops queries that would create more than 500 joined rows or take too much work.

It reads your text only to run it. Nothing is executed as program code, nothing is sent anywhere and the query is forgotten when you leave the page.

Where does it connect to the lessons?

The sandbox supports writing simple SQL queries within syllabus scope and SQL reasoning in a fictional database. Two focused pages follow on row filtering versus group filtering and on aggregates with empty groups and missing values.

If explaining your queries is the weak spot, SPM Computer Science tuition gives you a teacher to reason through them with you. It starts with the one-hour trial class (from RM50).

Common questions

Can this tool delete or change the data?

No. Only SELECT is understood. DELETE, UPDATE, INSERT, DROP and CREATE are refused with a message, and a second statement after a semicolon is refused too. The data is bundled and fictional, and nothing is saved.

Why does my query return nothing?

An empty result is a valid answer meaning no row matched. Check the WHERE condition, the JOIN condition and whether the value you compare really exists. The stage list shows how many rows survived each step.

What is the difference between WHERE and HAVING?

WHERE filters individual rows before grouping. HAVING filters groups after GROUP BY, so it can use COUNT or AVG. The tool rejects an aggregate inside WHERE and points you to HAVING.

Is this exactly how every database behaves?

No. It is a deliberately limited learner tool with a small part of SQL. Real systems support more, and dialects differ. Use it to understand the ideas, and follow your syllabus for what you must write.

A teacher working one-to-one can read a query with you line by line and ask what each clause does to the rows, so you can explain and write queries yourself instead of copying them.

  • Online one-to-one lessons for your child with an experienced teacher.
  • Your first class is a one-hour trial, from RM50. The fee is agreed before you book.
  • Happy with the teacher? Continue with lessons of about 1.5 hours. If not, ask for another teacher.