Go Back   SitePoint Forums > Forum Index > Program Your Site > Databases > MySQL
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old Sep 14, 2004, 10:38   #1
gdtrfb
SitePoint Zealot
 
Join Date: Sep 2004
Location: Boston
Posts: 174
Variable number of columns

Maybe this is an easy problem, maybe it isn't...but I'm sure it's been solved a million times before so I'm hoping the Collective Knowledge will come through here...

I have a table that looks like this:

widgetID (INT)
attributeID (INT)
attribute_value (varchar)

The table has a compound primary key consisting of the widgetID and the attributeID. These relate to other tables that give us attribute_name and widget_type, etc. but that's not pertinent to this discussion.

There can be a variable number of records in the table for a given widgetID. All widgetIDs do not have the same number of attributes. Some widgetIDs share common attributes, some attributes are unique to specific widgetIDs.

I need to generate a report that looks like this

widgetID attr1 attr2 attr3 ... attrN

for all the records in the widget_attribute table. Remember that the number of attributes per widget is variable and can be as high as 20 or more. And count(distinct(attributeID)) is currently over 100.

I know, it's a big messy table but that's what they want.

I'm currently doing this with a couple temporary tables and loops but that's taking forever. I'm hoping there's an elegant solution to this type of problem.

Thanks!
gdtrfb is offline   Reply With Quote
 

Bookmarks

« Previous Thread | Next Thread »

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 02:10.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved