SQL JOIN Generator
Joining several tables means knowing which columns connect them. Paste your CREATE TABLE statements, choose the table to start from and tick the tables you need, and the generator finds the path through the foreign keys, including linking tables in many-to-many relations, and writes the JOIN query with short aliases, correct ON conditions and column names that do not clash.
- Runs in your browser
- No sign-up
- Free to use
How to use SQL JOIN Generator
- Paste the CREATE TABLE statements with their foreign keys.
- Choose the starting table.
- Tick the tables to join and choose INNER or LEFT JOIN.
- Copy the query and add your conditions.
SQL JOIN Generator features
Path finding
Shortest foreign-key path between tables, in either direction.
Linking tables
Many-to-many junction tables added automatically.
Aliases
Short, unique aliases such as o, c and oi.
Column naming
table_column aliases, alias.* or keys and names only.
Join types
INNER JOIN or LEFT JOIN with guidance on conditions.
Fan-out warning
Explains when rows will repeat.
When to use SQL JOIN Generator
- Writing a report that combines orders, customers and products.
- Exploring an unfamiliar database schema.
- Getting many-to-many joins right on the first try.
- Building views over normalised tables.
SQL JOIN Generator FAQ
How are the joins found?
Every foreign key is treated as a connection between two tables. A breadth-first search finds the shortest path from the starting table to each selected table.
What happens with many-to-many relations?
If posts and tags are connected through post_tags, selecting tags from posts automatically adds the post_tags join in between.
INNER or LEFT JOIN?
INNER JOIN keeps only rows with a match in every table. LEFT JOIN keeps every row of the starting table and fills missing matches with NULL.
Why do rows repeat?
Joining from one row to many, such as an order to its items, returns the order once per item. Aggregate with GROUP BY or use a subquery if you need one row per order.
Why put conditions in ON with a LEFT JOIN?
A WHERE condition on the joined table removes the NULL rows a LEFT JOIN produces, turning it into an inner join.
Is anything uploaded?
No. The query is generated in your browser.
Joins from the schema itself
In a normalised database, information about one thing is spread over several tables connected by foreign keys. Every report or screen that combines them needs JOIN clauses, and writing them requires knowing which column refers to which. The schema already contains that knowledge, so the generator reads it and writes the joins.
Each foreign key becomes an edge in a graph of tables. From the starting table, a breadth-first search finds the shortest path to each table you select, following foreign keys in both directions. Paths share their common parts, so joining customers and products from orders adds order_items once.
Many-to-many relationships are the classic difficulty: posts and tags are not connected directly but through a linking table. Because the search follows any foreign key, the linking table appears on the path and its join is added, with a note listing tables that were included automatically.
Aliases are built from the initials of each table name and made unique, so order_items becomes oi. Columns can be listed with table_column aliases, which avoids clashes between columns such as id and name, or as alias.* for quick exploration, or reduced to keys and descriptive columns.
The notes explain the behaviour of the result. Joining from one row to many repeats the starting rows, LEFT JOIN conditions belong in the ON clause, and INNER JOIN drops rows without matches. Add your WHERE, GROUP BY and ORDER BY clauses to the generated query.