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 > Query Question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-09-11, 13:16
lightfju lightfju is offline
Registered User
 
Join Date: Sep 2010
Posts: 14
Query Question

This may be a carzy question but here it goes any way:

Would it be possible to show the same column 3 different times with different data in each column. For example, the way that the programmer created the DB The user enters an event and then a date for the event. A single client may have 8 events. I would like a different column for each event with the date under that, much like an Excel document, showing all events on one line thus have the client name only taking a single line.
Reply With Quote
  #2 (permalink)  
Old 11-09-11, 14:49
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
what you're asking for is called a "crosstab" layout

this is not a task that the database engine should be asked to perform

to give you a feeling for why, it's because in order to have separate columns for each event, you would have to hardcode the conditional expression for each column in the sql, and this is bloated, awkward and prone to error (i mean, look, you started out talking about 3, then suddenly there were 8...)

do the crosstab in your application language (php or whatever)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-10-11, 15:24
lightfju lightfju is offline
Registered User
 
Join Date: Sep 2010
Posts: 14
Thanks for the reply!! I figured that but needed to have "proof" for my supervisors...

By the way I love your book!!! Almost through it a 2nd time
Reply With Quote
  #4 (permalink)  
Old 11-10-11, 17:39
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
thanks for the kind words

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Tags
mysql, query, sql

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