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?
1 Answer
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;
Demo
1 Comment
Suzy Tros
is mod necessary? any other way?