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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:01:03+00:00 2026-05-27T02:01:03+00:00

I am having a problem getting multiple attributes for one item. Below is my

  • 0

I am having a problem getting multiple attributes for one item. Below is my Table:

Table: product_attrib

id | product_id | name | value 
------------------------------
 0 |         33 | age  |   25
 1 |         33 | size |   25

My problem is when I join the query, I only get one of the attributes with such a query:

Query:

SELECT 
    p.*
    ,pa.name
    ,pa.value
FROM product AS p
LEFT OUTER JOIN product_attrib AS pa ON (
    p.id = pa.product_id
)

My Results

"products_id":"0",
"products_price":"0.0000",
"products_name":null,
"products_description":null,
"attrib_name":"color",
"attrib_value":"red"

Do you see how I only get one attribute set?
Is there a way I can get all the attributes for a product?

  • 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-27T02:01:04+00:00Added an answer on May 27, 2026 at 2:01 am

    Most likely, your original query is right as it is. You probably want the product, no matter if attributes can be found.

    You can reverse the order of the tables in the JOIN to prevent losing rows from product_attrib like this (if product with product_id 33 does not exist):

    SELECT
         p.*
        ,pa.name
        ,pa.value
    FROM product_attrib AS pa 
    LEFT JOIN product AS p ON p.id = pa.product_id
    

    But that’s probably not what you want.

    A LEFT [OUTER] JOIN includes all rows from the left hand table and adds values from the right table where the JOIN condition can be fulfilled (potentially creating multiple rows if multiple matches are found in the right hand table.) If no matching row can be found in the right hand table NULL values are substituted for all columns of the right hand table.
    Start by reading the manual here.

    If you want “all attributes” per product in the same row, you need to aggregate values. Something like this:

    SELECT p.*
          ,group_concat(pa.name) AS att_names
          ,group_concat(pa.value) AS att_values
    FROM  product AS p
    LEFT  JOIN product_attrib AS pa ON p.id = pa.product_id
    WHERE p.product_id = 33
    GROUP BY p.*;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having a problem getting a TreeView control to display node images. The code below
I am having a problem with getting the listviewitems to size to the space
Hi im having an interesting problem. Update: From the comments im getting below this
I am having problem getting my tooltip to work when using the jQuery load()
I am having a problem getting a list of fields from a query defined
I'm having a problem getting access to a database which lives on a remote
I am having a problem getting my project to link with the PhysX libraries
I'm having a problem getting a simple ASP.NET webpage to display. The page contains
I'm having a problem getting a change event to register with the following code:
I'm having a problem getting XCode to deal with a particular file structure that

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.