SQL Study Guide

Interactive SQL practice page

Use these examples to learn common commands, join patterns, and safer SQL habits. This page is designed for study and demo use on the shared site at meatgon.com/sql.

Quick starter

Core commands

This demo uses a small in-memory customer table so you can see results and errors.
Execution preview

Click Execute to run the current query and see the result or error.

Join examples

Joins combine rows from multiple tables using a related column.

Example SQL script

CREATE TABLE customers (
  customer_id INT PRIMARY KEY,
  customer_name VARCHAR(100),
  city VARCHAR(100)
);

CREATE TABLE orders (
  order_id INT PRIMARY KEY,
  customer_id INT,
  total DECIMAL(10,2)
);

INSERT INTO customers VALUES (1, 'Mina', 'Seattle');
INSERT INTO customers VALUES (2, 'Leo', 'Denver');

INSERT INTO orders VALUES (101, 1, 45.00);
INSERT INTO orders VALUES (102, 2, 80.00);

SELECT c.customer_name, o.order_id, o.total
FROM customers c
INNER JOIN orders o ON c.customer_id = o.customer_id;

Prevent SQL injection

The safest approach is to use parameterized queries instead of concatenating input into SQL text.

  • Use prepared statements and bound parameters.
  • Validate and whitelist user input before using it.
  • Use the least-privilege database account for the app.
  • Avoid building SQL with string concatenation like "SELECT * FROM users WHERE name = '" + input + "'".

Example

// Safe example in PHP
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->execute([":username" => $userInput]);