> ID ProductID OptionName OptionValue SKU
>
> 1 709 Title Como test
> 2 709 Color Cobalt test
> 3 709 Color Crimson RNA.331.02.MM1K
> 4 709 Title Como G2 RNA.331.02.MM1K
> 7 709 Color another color test ipn
> 8 709 Title another title test ipn
From the above table i want the following
Select distinct OptionName from myTable where ProductID = 709 group by OptionValue
but sql server is giving error on the group by clause and dont know how can i have all the different values grouped to distinct OptionName?
or i just can not ?
the result i want is as follows
[0] => array
[Color] => array
[0] => Cobalt test
[1] => Crimson
[2] => another color
[Title] => array
[0] => Como test
[1] => Como G2
[2] => another title
You need to use an aggregate function on the fields (like FIRST(), LAST(), MAX(), AVG() …) you are selecting when you have a GROUP BY-clause. Also, distinct is not necessary when you have GROUP BY. Can you explain what data you want to extract and not only post a faulty query?
EDIT:
Will produce this:
Converting to arrays etc. is something you have to do in your application, not with SQL.