0

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 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

is mod necessary? any other way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.