Loading…
A foreign key is a column that references the primary key of another table. It creates a relationship between tables.
-- sessions.user_id → users.id
-- This means every session belongs to a user
| sessions | users | |
|---|---|---|
| session_id (PK) | id (PK) | |
| user_id (FK) | → | id |
| started_at | username |
Use the foreign key relationship to find which users have sessions:
Downloading SQL engine… (one-time)
This runs entirely in your browser and is cached for next time.