Reference

API Documentation

Read-only REST access to classic sample databases across two engines — SQL Server (primary) and MySQL/MariaDB. Every response echoes the exact sql it ran, so you learn the query behind each call.

Getting started

No key, no login — make a request with any HTTP client. The fastest way to explore is the interactive playground, which builds these URLs for you.

# List everything available (engines + databases)
curl "https://learnsql.cpetoday.com/api/catalog"

# Get 5 customers from the Northwind database on SQL Server
curl "https://learnsql.cpetoday.com/api/mssql/northwind/Customers?limit=5"

URL structure

Data endpoints are scoped by engine and database, so one API serves every dataset:

/api/{engine}/{database}/{table}
  • {engine}mssql (SQL Server, primary) or mysql (MySQL/MariaDB)
  • {database} — one of the databases below (e.g. northwind)
  • {table} — a table in that database (case-insensitive)

Names with spaces & symbols

Several sample databases (like Northwind) have table/column names with spaces or slashes — Order Details, Country/Region. URL-encode spaces as %20 in both the path and query string. The playground does this for you.

Available databases

SQL Server (mssql) — primary:

adventureworksclassicmodels contosodvdrental northwindqbd qbosage100 worldxtreme

MySQL / MariaDB (mysql) — secondary:

acmeadventureworks classicmodelsnorthwind world

This list is live — call GET /api/catalog for the authoritative set. (These pills update automatically.)

Endpoints

GET /api/catalog

List all engines and their databases.

GET /api/{engine}/{database}/tables

List every table in a database.

GET /api/{engine}/{database}/{table}/schema

Column names, types, nullability, and primary key for a table.

GET /api/{engine}/{database}/{table}

Rows from a table, with pagination, field selection, and sorting.

GET /api/{engine}/{database}/{table}/{id}

A single row by its primary-key value.

GET /api/{engine}/{database}/{table}/aggregate

COUNT / SUM / AVG / MIN / MAX, optionally grouped by a column.

GET /api/{engine}/{database}/{t1}/join/{t2}

Inner-join two tables and return the combined rows.

GET /api/{engine}/{database}/schema-map

Every table, its columns/PKs and all declared foreign keys in one call (powers the schema explorer).

Legacy shortcut

Older URLs without an engine/database — /api/tables, /api/Customer — still work and default to the mysql / acme dataset.

Query parameters

List endpoint /{table}

ParameterDescriptionDefault
pagePage number (1-based)1
limitRows per page (max 10000)1000
fieldsComma-separated columns to returnall
sortColumn to sort byprimary key
orderASC or DESCASC

Aggregate endpoint /aggregate

ParameterDescriptionRequired
operationcount, sum, avg, min, maxyes
fieldColumn to aggregate (use * with count)yes
group_byColumn to group results byno

Join endpoint /join/

ParameterDescriptionRequired
onColumn with the same name in both tablesone of these
left + rightKey names when they differ per table (e.g. ?left=Customer&right=Company)one of these
fieldsCustom select list (use t1./t2. aliases)no
limitRows to return (max 1000)no

Guided examples

The same five requests in three languages — copy, run, tweak.

# 1 · What tables are in Northwind?
curl "https://learnsql.cpetoday.com/api/mssql/northwind/tables"

# 2 · First 5 customers, only two columns
curl "https://learnsql.cpetoday.com/api/mssql/northwind/Customers?limit=5&fields=ID,Company"

# 3 · One customer by primary key
curl "https://learnsql.cpetoday.com/api/mssql/northwind/Customers/1"

# 4 · Count customers by country
curl "https://learnsql.cpetoday.com/api/mssql/northwind/Customers/aggregate?operation=count&field=*&group_by=Country/Region"

# 5 · Join orders to customers on differently-named keys
curl "https://learnsql.cpetoday.com/api/mssql/northwind/Orders/join/Customers?left=Customer&right=Company&limit=10"
import requests

BASE = "https://learnsql.cpetoday.com/api"

# First 5 customers, two columns
r = requests.get(f"{BASE}/mssql/northwind/Customers",
                 params={"limit": 5, "fields": "ID,Company"})
data = r.json()
print(data["sql"])          # the exact SQL that ran
for row in data["data"]:
    print(row)
const BASE = "https://learnsql.cpetoday.com/api";

// Count customers by country
const url = `${BASE}/mssql/northwind/Customers/aggregate` +
  `?operation=count&field=*&group_by=Country/Region`;

const res  = await fetch(url);
const data = await res.json();
console.log(data.sql);       // learn the SQL
console.table(data.results); // [{ group, value }, …]

Response format

List responses include the data, pagination metadata, and the SQL that ran:

{
  "engine": "mssql",
  "database": "northwind",
  "table": "Customers",
  "data": [ { "ID": 1, "Company": "Alfreds Futterkiste" } ],
  "pagination": { "page": 1, "limit": 5, "total": 91, "pages": 19 },
  "sql": "SELECT [ID], [Company] FROM [northwind].[Customers] ORDER BY [ID] ASC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY"
}

The SQL echo

Every data endpoint returns a sql field containing the exact query the API executed against the real database — bracket-quoted identifiers, schema qualification, engine-specific pagination and all. It’s the core teaching feature: build a request, then read the SQL you effectively just wrote and paste it into any SQL client to keep learning.

Errors

Errors return JSON with an error message and an HTTP status:

StatusMeaning
400Bad request — invalid parameter, field, or query
404Unknown engine, database, table, or record
500Server or database connection problem
{ "error": "Table 'Customerz' doesn't exist" }

Using from your tools

Responses are plain JSON over HTTP, so you can consume the API from code or everyday desktop tools:

  • Python: requests.get(url).json()
  • JavaScript: fetch(url).then(r => r.json())
  • Excel / Power BI: Power Query → From Web, paste an /api/… URL

Connect Microsoft Excel

Follow the Excel & ODBC connection guide to pull the sample databases straight into Excel — natively, via ODBC Driver 18, or through this API with Power Query.