Skip to content

Relationships and Queries

Continue in the database created in Your First Database. Its three employees include Clara, whose department is not specified.

A foreign key stores the department identifier. To read its name, combine employees and departments using a join:

SELECT e.name, d.name AS department
FROM employees AS e
LEFT JOIN departments AS d ON e.department_id = d.id
ORDER BY e.id;
name department
Alice Engineering
Boris Support
Clara NULL

LEFT JOIN retains each employee even if there is no matching department. The selected department name is then NULL. An inner join would omit employees without a matching department.

RadixDB can derive the same relationship from the declared foreign key:

SELECT e.name, e.department_id.name AS department
FROM employees AS e
ORDER BY e.id;

The result is the same table. The alias e selects the employee row, department_id is its foreign-key column, and name belongs to the referenced department. Reading e.department_id alone still returns the key value.

Navigation is a query notation, not an object stored in the column. This example follows one declared relationship and does not establish support for arbitrary graph traversal or updates through a path.

The SQL chapter Navigable References covers transitive paths, NULL, grouping, diagnostics and the permanent write boundary.

Continue with transactions.