Relational Integrity
GhostSQL implements standard relational features to ensure data consistency.
Primary Keys
Ensure each row is unique:
Foreign Keys
Link tables together and enforce referential integrity:
CREATE TABLE departments (
id INT PRIMARY KEY,
name TEXT
);
CREATE TABLE employees (
id INT PRIMARY KEY,
name TEXT,
dept_id INT REFERENCES departments(id)
);
Joins
GhostSQL supports all major JOIN types:
- INNER JOIN: Only rows with matches in both tables.
- LEFT JOIN: All rows from the left table, plus matches from the right.
- RIGHT JOIN: All rows from the right table, plus matches from the left.
- FULL OUTER JOIN: All rows from both tables, with NULLs where no match exists.
- CROSS JOIN: Cartesian product of both tables.
Join Example
Aggregates & Grouping
GhostSQL supports standard aggregate functions and grouping:
- COUNT(*) / COUNT(column)
- SUM(column)
- AVG(column)
- MIN(column) / MAX(column)
Example: Salary Analysis
Mathematical Expressions
You can perform arithmetic operations directly in your queries: