QA StepsLog in

SQL sandbox with the course database

The Shelf online-shop database from the course "SQL for Testers: A Working Day". Change the data and create tables: the reset button brings the database back to its original state.

  • SQLite 3.49, the same as the check in QA Steps
  • Tables: 7
  • No sign-up; the database lives in this tab

Query the database

Tables and columns: click a name to insert it
  • (, , , )
  • (, , , , , , , , , , , , , , , , , )
  • (, , , , , , , , , )
  • (, , , , , )
  • (, , , , , )
  • (, , , )
  • (, , , )
The database is loading…

Where the same query gives a different answer

The SQL day course teaches on SQLite 3.49, the same engine as QA Steps and this sandbox. At work you will most often meet MySQL or PostgreSQL. Almost everything in the course works the same on all three, but in the rows below the answers differ. All three columns were run on the same Shelf database.

What is comparedMySQL 8.4QA Steps and sandbox (SQLite 3.49)PostgreSQL

Letter case in comparison

SELECT id, status FROM orders WHERE status = 'Paid';
8 rows: MySQL treats 'Paid' and 'paid' as the sameEmpty: case mattersEmpty, same as SQLite

Accented letters

SELECT 'café' = 'cafe' AS same;
1: MySQL ignores accents, so café and cafe are equal0: they are different stringsfalse

LIKE and letter case

SELECT id, subject FROM support_tickets WHERE subject LIKE '%CHARGED%';
3 tickets: LIKE ignores case3 tickets: SQLite ignores case for Latin lettersEmpty: LIKE is case-sensitive, and ILIKE searches without case

Integer division

SELECT 7 / 2 AS half;
3.50003: the fraction is dropped3, same as SQLite

Shape of an average

SELECT AVG(amount_cents) AS avg_payment FROM payments;
19726.615419726.61538461538319726.615384615385

Joining strings with ||

SELECT 'a' || 'b' AS glued, CONCAT('a', 'b') AS same_everywhere;
0: in MySQL || is a logical OR. CONCAT gives abab and abab and ab

A column outside GROUP BY

SELECT user_id, status, COUNT(*) AS orders_count FROM orders GROUP BY user_id;
Error 1055Runs and takes status from any row of the groupError, same as MySQL

Group order without ORDER BY

SELECT status, COUNT(*) AS orders_count FROM orders GROUP BY status;
paid, cancelled, awaiting_payment: in the order they first appear in the tableawaiting_payment, cancelled, paid: alphabeticalAny order: without ORDER BY none is promised

FULL OUTER JOIN

SELECT o.id AS order_id, p.id AS payment_id FROM orders o FULL OUTER JOIN payments p ON p.order_id = o.id;
Error: MySQL has no full join, so it is built from LEFT JOIN, UNION and RIGHT JOIN17 rows17 rows

Casting to an integer

SELECT CAST(2.6 AS SIGNED) AS signed_int, CAST(2.6 AS INTEGER) AS integer_int;
AS SIGNED gives 3, and AS INTEGER gives an error3 and 2: AS SIGNED is rewritten to CAST(ROUND(x) AS INTEGER), and AS INTEGER drops the fractionSIGNED is unknown, and AS INTEGER rounds to 3

TRUNCATE inside a transaction

START TRANSACTION; TRUNCATE TABLE payments; ROLLBACK; SELECT COUNT(*) AS payments_left FROM payments;
0: TRUNCATE ends the transaction, so ROLLBACK brings nothing back13: TRUNCATE runs as DELETE, and ROLLBACK undoes it13: ROLLBACK brings the table back

Foreign keys

PRAGMA foreign_keys;
Enforced: the database rejects a row that points nowhereNot enforced (0). In the sandbox, PRAGMA foreign_keys = ON; turns the check onEnforced

VARCHAR(n) length

CREATE TABLE notes (title VARCHAR(5)); INSERT INTO notes VALUES ('far too long'); SELECT title FROM notes;
Error 1406: a string longer than n does not fitStores the whole string: SQLite does not check the lengthError, same as MySQL

The empty value

SELECT IFNULL(NULL, 0) AS a, COALESCE(NULL, 0) AS b;
Both functions workBoth functions workThere is no IFNULL, only COALESCE works

Name of the current database

SELECT DATABASE();
The database nameError: there is only one database, and no such functionThere is no such function, use current_database() instead

Error text

SELECT nickname FROM users;
Unknown column 'nickname' in 'field list'no such column: nicknamecolumn "nickname" does not exist

What is rewritten automatically

Queries written for MySQL are common in tutorials. So that they run on SQLite, the sandbox and the task check in QA Steps replace four constructs before running. Everything else runs as written.

Where to learn next

The SQL course takes you through this database from your first SELECT to accepting a migration. The other courses on the platform teach testing as a whole, from theory to the resume and the interview.

Cookies keep you signed in. With your OK, one more remembers which link brought you here. Learn more