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 8222171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:11:15+00:00 2026-06-07T14:11:15+00:00

I have the following table named attributes : | identifier | attribute | value

  • 0

I have the following table named attributes:

| identifier | attribute | value      |
|------------|-----------|------------|
| 23         | myKey     | myValue    |
| 24         | hisKey    | hisValue   |
| 25         | herKey    | herValue   |
| 23         | otherKey  | otherValue |

I would like to make SQL select query which selects the above rows, groups them by their identifier and uses the attribute as the key and the value as value for the key.

This means that the a table which looks like the above, should turn into the following PHP array:

Array
(
    [0] => Array
        (
            [identifier] => 23
            [myKey] => myValue
            [otherKey] => otherValue
        )

    [1] => Array
        (
            [identifier] => 24
            [hisKey] => hisValue
        )

    [2] => Array
        (
            [identifier] => 25
            [herKey] => herValue
        )

)

I have tried the following SQL query:

SELECT attributes.value as atttributes.attribute FROM attributes GROUP BY identifier

This will give the following error:

Uncaught exception ‘PDOException’ with message ‘SQLSTATE[42000]:
Syntax error or access violation: 1064 You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near ‘.attribute FROM attributes GROUP BY
identifier’ at line 1′

Does anyone know of a way to do this?

  • 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-06-07T14:11:16+00:00Added an answer on June 7, 2026 at 2:11 pm

    Your error is from a typo. Don’t specify the table in an alias.

    SELECT attributes.value as atttributes.attribute FROM attributes GROUP
    BY identifier

    Here’s the correction:

    SELECT attributes.value as attribute FROM attributes GROUP BY identifier
    

    However, it won’t get you want you want. MySQL will always return results with the same number of columns in each row.

    You’ll need to implement this in code with a loop. Instead of GROUP BY, use an ORDER BY, and whenever the identifier changes, start another array.

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

Sidebar

Related Questions

i have a table named item with four attribute name,code,class,value now i want to
I have a following table named [clients] with columns and values as follows: +--------+-----------+--------------+----------------+
I have a table named friends with following structure: id, from_id, to_id, confirmed, ....
I have a table named with Sales having the following columns: Sales_ID|Product_Code|Zone|District|State|Distributor|Total_Sales Now i
So I have two tables. Table 1 is named 'appointment' with the following fields:
I have a table named item with two attributes ( code and name ).
I have the following database -- MYSQL DROP TABLE IF EXISTS Attributes; DROP TABLE
I have following mapping definitions: <class name=Role table=Role optimistic-lock=version > <id name=Id type=Int32 unsaved-value=0
Rails 3 problem. I have a Foods table of foods with the following attributes:
I have one table contains field named source with varchar(max). That field has following

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.