If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Make Rows Columns

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-26-08, 14:53
isabelle isabelle is offline
Registered User
 
Join Date: Feb 2004
Posts: 3
Question Make Rows Columns

I have a table with 2 Columns and an indefinite number of rows:
QuestionItemTypeID Question
99DDB761-703D-4F8A-9859-0F4A7455A135 Backup Training Plan
C828FAF5-864F-4E9A-A6D4-0FB9F8E744DE System Applications Load
6CC0EDEB-179C-4F81-ABD6-138CC23FFD32 Which Organization?
16E0A8D7-5C55-4315-A9DD-1746822F5FCD Is the network cable plugged in?
… …

I need for each question to become the columns of a new table.
Reply With Quote
  #2 (permalink)  
Old 02-26-08, 15:31
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
export this table to a csv file
import to excel
write a transpose/pivot routine in excel
import the resulting table back into mysql
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-26-08, 15:37
isabelle isabelle is offline
Registered User
 
Join Date: Feb 2004
Posts: 3
Thank you.
Is there any ways to accomplish it within SQL?


--> I used a cursor and added the columns dynamically.
That works. Just hoped for a SQL function...

Last edited by isabelle; 02-26-08 at 16:33.
Reply With Quote
  #4 (permalink)  
Old 02-28-08, 12:13
laddy7690 laddy7690 is offline
Registered User
 
Join Date: Feb 2008
Posts: 3
Standard SQL does not support this.

Some vendors provide prioprietary pivoting functions that may allowed you to do it, but you will need some kind of pivoting tool.

Last edited by r937; 02-28-08 at 12:38.
Reply With Quote
  #5 (permalink)  
Old 02-28-08, 12:39
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by laddy7690
Standard SQL does not support this.
there is no built-in function for it, no, but it is certainly possible to do this with standard sql

just very very clumsy

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 02-28-08, 15:05
laddy7690 laddy7690 is offline
Registered User
 
Join Date: Feb 2008
Posts: 3
You're right.

I thought she was importing a file into a table, not querying an existing table.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On