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 8680311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:12:57+00:00 2026-06-12T21:12:57+00:00

I’ve a TableOriginal that I want to split into multiple tables, each one with

  • 0

I’ve a “TableOriginal” that I want to “split” into multiple tables, each one with the name of the different values than can be found on “split” column in “tableOriginal“. The name, therefore, must be dynamic (maybe formed by a variable that is the result of a previous query).

TableOriginal:

+----+-------+-------+
| id | split | value |
+----+-------+-------+
| 1  |   A   |  v1   |
| 2  |   A   |  v2   |
| 3  |   A   |  v3   |
| 4  |   B   |  v4   |
| 5  |   B   |  v5   |
| 6  |   B   |  v6   |
| 7  |   C   |  v7   |
| 8  |   C   |  v8   |
| 9  |   A   |  v9   |
| 10 |   B   |  v10  |
| 11 |   B   |  v11  |
| 12 |   C   |  v12  |
+----+-------+-------+

TableSplit_A

+----+-------------+-------+
| id | original_id | value |
+----+-------------+-------+
| 1  |      1      |  v1   |
| 2  |      2      |  v2   |
| 3  |      3      |  v3   |
| 4  |      9      |  v9   |
+----+-------------+-------+

TableSplit_B

+----+-------------+-------+
| id | original_id | value |
+----+-------------+-------+
| 1  |      4      |  v4   |
| 2  |      5      |  v5   |
| 3  |      6      |  v6   |
| 4  |      10     |  v10  |
| 5  |      11     |  v11  |
+----+-------------+-------+

TableSplit_C

+----+-------------+-------+
| id | original_id | value |
+----+-------------+-------+
| 1  |      7      |  v7   |
| 2  |      8      |  v8   |
| 3  |      12     |  v12  |
+----+-------------+-------+

SQLFiddle:

http://sqlfiddle.com/#!2/61266

  • 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-06-12T21:12:59+00:00Added an answer on June 12, 2026 at 9:12 pm

    You can probably use VIEW for this. For the dynamic approach see the TEMPTABLE argument to the VIEW.

    In the VIEW’s Create query you then use alias for the column name.

    In my opinion dynamics in relation should be handled in code and not in procedures on server. Anyways, here’s an example:

    CREATE ALGORITHM=UNDEFINED 
    DEFINER=`user`@`yourserver` 
    SQL SECURITY DEFINER 
    VIEW `tableA` AS select `tableoriginal`.`id` AS `id`,
         `tableoriginal`.`split` AS `tableoriginal_A`,
         `tableoriginal`.`value` AS `value` 
    from 
         `tableoriginal` 
    where
         (`tableoriginal`.`split` = 'A')
    

    Now you can query TableA as any other table (I skipped the TEMPTABLE in this example).

    Hope this was related to what you where looking for.

    Added to fiddler:
    http://sqlfiddle.com/#!2/c4304/1

    UPDATE: (based on the comments below)

    Personally I work by the STORE-NOP principle 😛 use a database only to STOre-REtrieve-NOt-for-Processing ™, so I would do it in two steps:

    select distinct split from TableOriginal;
    

    Then go through each result and inject the result in a pre-defined query (notice {0} in the string, these will be replaced later – and perhaps different in the language you’re using):

    myView = "CREATE ALGORITHM=UNDEFINED 
    SQL SECURITY DEFINER 
    VIEW `table{0}` AS select `tableoriginal`.`id` AS `id`,
         `tableoriginal`.`split` AS `tableoriginal_{0}`,
         `tableoriginal`.`value` AS `value` 
    from 
         `tableoriginal` 
    where
         (`tableoriginal`.`split` = '{0}')
    ;"
    

    Then run the query for each line in result (pseudo code in VB):

    For Each line In DBQueryResult
      cmd.ExecuteWrite(String.Format(myView, line.field("split"))
    Next
    

    I cannot check right now if these are valid statement, but it’s meant as pseudo code so you can get the idea how you can do this in the language you are using.

    You also might want to consider use a IF EXIST/DROP VIEW or a TEMPTABLE in the final query.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.