Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6926341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:54:22+00:00 2026-05-27T10:54:22+00:00

I have a 10 tables with the same schema. I’m trying to create an

  • 0

I have a 10 tables with the same schema. I’m trying to create an overloaded stored procedure so that I can union a bunch of tables together with simple selects (SELECT * FROM tableX). If each table has 1000 (different) rows, then I want to create a stored procedure where the following would happen:

CALL getRowsByNum(table1); -> 1000 rows
CALL getRowsByNum(table1, table2, table4); -> 3000 rows

…etc.

I got part of the way through writing 10 overloaded procedures that would SELECT * FROM X UNION ALL SELECT * FROM X UNION ALL….. etc, but that’s really madness.

Anyone have a different suggestion? This silly setup is the result of an architectural decision made a while ago.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:54:22+00:00Added an answer on May 27, 2026 at 10:54 am

    Not really. You can’t have variable number of parameters or procedures with the same name.

    I dont think there is an easy solution to your problem.

    EDIT: I’ve thought of an really ugly solution but I’ll leave it to you if you wanna use it. This is untested pseudo code only.

    Create a proc where you take a varchar in, long enough to hold the value “table1,table2,table3,…” and so on for as many tables you like to union at most. (could be another identifier of course)

    Write all tables in union. Since they are the same just use * to save time and space

    delimiter //
    
    create procedure megaunion (tables varchar(255)) 
    begin 
       select * from table1 where find_in_set('table1', tables)   
       union
       select * from table2 where find_in_set('table2', tables)
       ....
    end//
    

    list all your tables. At least you don’t have to list the possible permutations and the user of the procedure won’t know how you did it 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 tables with the same schema, one is just a table that
I have four tables containing exactly the same columns, and want to create a
I have two tables, A and B, that have the same structure (about 30+
I have two tables both have same schema, one will have previous day records
I've got a bunch of strongly typed DataSet that each have two tables. One
I have two tables (with the same schema) Table1 id title D0 D1 D2
In my DB schema I have several tables that will be related to a
I have several databases that have tables with the same name. I mean, I
I have table1 and table2 that have the same schema... and I want to
I have two tables with the exact same schema in SQL Server 2008 Standard

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.