Reputation: 373
I have a table filled with 1000 last names and a table filled with 100 first names. I want to create a new table with these 1000 last names and 100 first names on repeat. How can I do this in postgreSQL
?
Upvotes: 0
Views: 63
Reputation: 39477
If I understand this right, you want to list all the 1000 last names and the 100 first names repeating 10 times.
Try something like this:
select *
from (
select l.*,
row_number() over (order by ?) as rn
from last_names l
) l
join (
select f.*,
row_number() over (order by ?) as rn,
count(*) over () as total_count
from first_names f
) f on mod(l.rn - 1, total_count) = f.rn - 1;
Upvotes: 1