SQL: joining multiples tables into one.

Posted by Graveen on Stack Overflow See other posts from Stack Overflow or by Graveen
Published on 2010-05-13T14:38:54Z Indexed on 2010/05/13 14:54 UTC
Read the original article Hit count: 173

Filed under:
|
|
|

I have 4 tables.

r1, r2, r3 and r4. The table columns are the following:

rId | rName

I want to have, in fine, an unique table - let's call it R. Obviously, R will have the following structure:

rTableName | rId | rName

I'm looking for a solution, and the more natural for me is to:

  1. add a single column to all rX
  2. insert this column the table name i'm processing
  3. generate SQLs and concatenate them all

Although I see exactly how to perform 1 and 3 with batching, editing, etc... (I have only to perform it once and for all), I don't see how to do the point 2: self-getting the tablename to insert into SQL.

Have you an idea / or a different way to do that could solve my problem?

Note: In fact, there are 250+ rX tables. That's why i can't do this manually. Note2: Precisely, this is with MySQL.

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql