Combine Records from Different Tables
Let's say you have 2 users and 3 categories and you want a query to return the combination of all the records, resulting in 6 rows.
You can use cross join
to do that:
select
users.id as user_id,
categories.id as category_id
from users cross join categories
user_id | category_id
---------+-------------
1 | 1
1 | 2
1 | 3
2 | 1
2 | 2
2 | 3
Tweet