Skip to content

SQL

SQL lets you ask a database questions about saved records and tell it how to change them. It is a language used by database systems such as PostgreSQL and SQLite.

Read official information

What is a useful first question to ask in SQL?

Try “Which orders are still open?” on three made-up orders. A query is an instruction you send to a database. Here the first two instructions set up practice records. The last instruction reads the matching rows.

If the SQLite command-line program is installed, open a fresh terminal session and run sqlite3 :memory: to start an empty database that disappears when you exit. Confirm you started this temporary session before pasting the example. Leave your app’s database and saved files alone.

You should see order 1 marked open, then order 3 marked open. Order 2 stays in the table and is left out of this result because it is marked sent. SELECT picks the columns to show. WHERE keeps rows that match. ORDER BY sets the order you see them in.

If you cannot confirm the temporary setup or do not have SQLite, try it on paper. Write down the three rows, cross out the ones whose status is different and check that the same two remain.

CREATE TABLE orders (order_id INTEGER, status TEXT);
INSERT INTO orders VALUES (1, 'open'), (2, 'sent'), (3, 'open');

SELECT order_id, status
FROM orders
WHERE status = 'open'
ORDER BY order_id;

How do you answer a question that needs two tables?

A join matches records across tables by a value they have in common. If an order contains a customer ID, a join can use that ID to find the corresponding customer.

Check what the database does when a matching row is missing. A query that should show every order can quietly leave some out if it requires every order to have a matching customer. Start with a practice set that includes one missing match and check whether that order should appear.

What changes when SQL can edit saved records?

An UPDATE or DELETE changes the data. A missing condition can change every row in a table. Practice on disposable records, and use an account with read-only access when your job is inspection.

A transaction can group changes so they succeed or roll back together. A database rule such as a unique constraint can reject a duplicate reservation even if two people click at nearly the same time. Decide what counts as a duplicate before asking for the rule.

Will the same SQL work after switching databases?

Some basics travel well. The databases may disagree about date functions, supported types or how a table can be changed. Those differences are part of each database’s dialect.

Save your table definitions, queries and a safe test dataset. Before switching engines, run the queries against the destination and check the results for missing rows, blanks and dates. SQL itself has no subscription. What you pay depends on the database software, service and hosting you choose.