0

I have an SQL table with name 'OLD' like this one:

  old_col1     old_col2
   title         News
   post       blablabla1
   title         Weather
   post       blablabla2

and I want to insert to another table 'NEW' that has columns: title and post

the values of old_col2 from table OLD. Table NEW should be like this:

  title       post
    News      blablabla1
   Weather    blablabla2

I only tried to fill column title with this query:

     INSERT INTO NEW (title)
     SELECT  old_col1 
     FROM OLD
     where old_col1 = 'title'
HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
michael
  • 57
  • 2
  • 10
  • Is there an ID in the OLD table connecting title and post? Or do we assume the blablabla's directly below the title record is the corresponding post? If an ID is available, then you may be able to run a customized [MySQL pivot query](http://stackoverflow.com/questions/7674786/mysql-pivot-table). – Parfait Jun 19 '15 at 23:09
  • How do you know which title goes with which post? – Tab Alleman Jun 22 '15 at 15:22

1 Answers1

0

You can try something like below. See a example http://sqlfiddle.com/#!9/14841/4

select a.old_col2, b.old_col2
from OLD a JOIN OLD b ON a.old_col2 <> b.old_col2;
Rahul
  • 76,197
  • 13
  • 71
  • 125