How the checking works
When you press Check my answer, the practice box runs your query on a fresh copy of the practice database and compares the rows it returns with the rows our answer returns.
- Column names do not matter.
SELECT COUNT(*)andSELECT COUNT(*) AS totalare both accepted. - The number and order of columns do matter. If the question asks for the name and the price, return those two, in that order.
- Row order matters only when the question asks for a sort. If it says "in alphabetical order" or "highest first", your
ORDER BYmust do that. - How you wrote the query does not matter. A join, a subquery or a
WITHstep are all fine if the rows match. Most questions have several correct answers.
A few exercises in the lessons on INSERT, UPDATE, DELETE and creating tables change the database instead of returning rows. Those cannot be checked by comparing rows, so they link to the lesson, where one answer is shown.
Getting the most from them
Do not open the answer too early. Being stuck for a few minutes is where the learning happens. Look at the practice database to check the table and column names, and reread the question for words such as "each", "only" and "at least", which usually point to GROUP BY, WHERE and HAVING.
Build the query in steps. Start with a plain SELECT * from the main table. Add the WHERE. Add the join. Add the grouping last. Run it after each step. A query that grows this way is nearly always right, and when it is wrong you know which step broke it.
After solving, compare. The lesson shows one answer. If yours differs, work out why both are correct. Seeing a second route to the same result is one of the fastest ways to improve.
Come back later. Exercises you solved a week ago are a good test of what has stayed. Mixing topics in one sitting is harder than doing one topic at a time, and makes the knowledge last longer.
This is an independent learning site. It is not connected with the makers of any database product. MySQL, PostgreSQL, SQL Server, Oracle and SQLite are named only so that you know where a piece of SQL works. The shop, its customers and its staff in the practice database are made up.