Slipt table mySQL

Hi,

I have a 'Main Table' with 8 values (per example) and want to split it in two like the image in attachment.

Basically, want I want is to put 1st main table value in Table A, 2nd main table value in Table B, 3th main table value in Table A, etc, etc.... until the last value.
Can you help me?

Thanks,
split-table.png
vmorais_Asked:
Who is Participating?
 
Serial326Connect With a Mentor Commented:
An easy way to do it would be to make two request (1 for each table)  to create your needed table

See the code below
Table A :
create table Table_A as
SELECT * FROM
(SELECT @row := @row + 1 as row, t.*
FROM Main_Table t, (SELECT @row := 0) r) e
WHERE row mod 2 = 1
 
Table B :
create table Table_B as
SELECT * FROM
(SELECT @row := @row + 1 as row, t.*
FROM Main_Table t, (SELECT @row := 0) r) e
WHERE row mod 2 = 0

Open in new window

0
 
racekCommented:
Serial326 - your solution is brilliant ... maybe step 2 can be done in another way...
Table A :
create table Table_A as
SELECT * FROM
(SELECT @row := @row + 1 as row, t.*
FROM Main_Table t, (SELECT @row := 0) r) e
WHERE row mod 2 = 1
 
create table Table_B as
SELECT * FROM  Main_Table WHERE id not in (SELECT id FROM Table_A);

Open in new window

0
 
vmorais_Author Commented:
excellent, thank you..

I am not just getting to put it in a stored procedure.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.