Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5932233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:48:22+00:00 2026-05-22T14:48:22+00:00

> ID ProductID OptionName OptionValue SKU > > 1 709 Title Como test >

  • 0
> 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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:48:22+00:00Added an answer on May 22, 2026 at 2:48 pm

    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:

    SELECT OptionName, OptionValue FROM myTable WHERE ProductID = 709 ORDER BY OptionName ASC
    

    Will produce this:

    > OptionName    OptionValue             
    > 
    > Color          Cobalt test
    > Color          Crimson                
    > Color          another color   
    > Title          Como   test    
    > Title          Como G2
    > Title          another title
    

    Converting to arrays etc. is something you have to do in your application, not with SQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making an android application,I have 4 textviews namely ProductId,Title,description,image.I want when i
I have one table orders with a foreing key ProductID. I want to show
I have a relation mapping table like this: attributeid bigint productid bigint To clean
The structure of the table testtable is id int primary key productid int attributeid
this is my sp: CREATE DEFINER=`root`@`localhost` PROCEDURE `getproductname`(in productid int , out productname varchar(200))
For my question lets consider the following sample table data: ProductID    ProductName    Price   Category 1                Apple                 5.00       Fruits
I have this method in cs page: public String getToolTip(Object productId, Object imgBtnId) {
i have 2 tables: tblItems ID | orderID | productID 1 1 2 2
In T-SQL, you can do this: SELECT ProductId, COALESCE(Price, 0) FROM Products How do
I have a stored procedure where i am passing a simple XML: '<Products><ProductId>1</ProductId><ProductId>2</ProductId></Products>' I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.