» Quick Links
You can make money on these forums
We Share profits with you
Google
Google Adsense
Google Adwords
YPN
Yahoo
MSN Search
Web Directories
Web Hosting
Web Hosting Offers
Hosting News
Suggestions
Link Building
Domain Names
PHP Forums
MySQL Forums
» More Links
OSP News
Reseller Hosting
Shared Hosting
Dedicated Servers
Google Adsense
Search Engine Marketing
Link Development
Affiliate Marketing


» Advertising
Multiple DC PR Check

Free SEO Tools


Go Back   Webmaster Forums > Website Developement / Programming > MySQL Forums

MySQL Forums Share Your Ideas and Tips about MYSQL. Ask questions about MYSQL. Table Design and Much More...

Reply
 
Thread Tools Display Modes
  #1  
Old 07-30-2006, 11:07 AM
heartthrob heartthrob is offline
Junior Member
 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
heartthrob is on a distinguished road
Question multiple rows in one row

Hey pals

If I have a table called Shows and another table called Reviews and the sample data looks as follows in the tables:

Shows Table
ShowID..............Title
1...............ShowTitle
2...............ShowTitle2

Reviews Table
ShowID..........PubID..........Review
1.................Pub1..............Rev1
1.................Pub2..............Rev2
1.................Pub4..............Rev4

How can I get the data to output on one line per ShowID with the PubID being the column headings and each corresponding Review to go under the appropriate PubID heading? So for example the above would look like this:

ShowID.......Title............Pub1..........Pub2.. ...........Pub3........Pub4
1..........ShowTitle..........Rev1...........Rev2. ..........NULL..........Rev4

Assume for ease that there are only 4 PubIDs so the PubID headings will only have to -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Revenue Sharing Ads ( ?):
  #2  
Old 07-30-2006, 11:09 AM
luminous luminous is offline
OSP Starters
 
Join Date: Jul 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
luminous is on a distinguished road
Default

CODE:

select Shows.ShowID
, Shows.Title
, max(case when Reviews.PubID = 'Pub1'
then Reviews.Review end) as Pub1
, max(case when Reviews.PubID = 'Pub2'
then Reviews.Review end) as Pub2
, max(case when Reviews.PubID = 'Pub3'
then Reviews.Review end) as Pub3
, max(case when Reviews.PubID = 'Pub4'
then Reviews.Review end) as Pub4
from Shows
inner
join Reviews
on Reviews.ShowID = Shows.ShowID
group
by Shows.ShowID
, Shows.Title
-- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple DC, Multiple URL Check Tool visioninfotech Google 4 04-08-2007 06:34 AM
deleting rows in database!! Miltan MySQL Forums 1 09-07-2006 08:57 AM
retrieve multiple values parrod ASP forums and Tips 1 08-10-2006 03:11 PM
multiple fields issue!! Gillian MySQL Forums 1 08-03-2006 10:28 AM
multiple databases!!! Carissa MySQL Forums 1 08-02-2006 11:53 AM


All times are GMT. The time now is 08:22 PM.