Hi,i have this tblProductAttribute with ProductAttributeID|ProductID|AttributeID|AttributeValue|
1|1|Blue
2|2|medium

(AttributeID 1 = Color,2= size)
i want to get result from select query like this
ProductName|Color|Size
sampleproduct|Blue|Medium

inshort i need to get row data to be the column name
please help me.thanks :-)

Recommended Answers

All 5 Replies

If you are using MS SQL you can do

SELECT column_name 
  FROM information_schema.columns
 WHERE table_name = 'yourtablename'
 ORDER BY ordinal_position

tnx for reply.but im using mysql.

select ProductID , max(case when AttributeID=1 then AttributeValue else null end) Color
, max(case when AttributeID=2 then AttributeValue else null end) Size from tblProductAttribute 
group by ProductID

@urtrivedi thanks you very much! i have another question,what if i have unknown number of attributes? In my program,the user can add attributes.

You can do this by using php code,
First you have to loop through attribute table and create dynamic query.

Then exucute that query to get the desired result

commented: right +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.