Showing results for 
Search instead for 
Did you mean: 

query all products that have the same custom attribute value

query all products that have the same custom attribute value



I need to query all products in my database that have the same custom attribute value. The end results is I need the product IDs


What tables do I need to JOIN? What would the script look like?


Re: query all products that have the same custom attribute value

Hi Justin,

All Attributes are stored in eav_attribute table you willnever need to join table you can write query filter by attribute


// Your Attribute code

	$products = Mage::getResourceModel('catalog/product_collection');
	// Select which fields to load into the product
	// * will load all fields but it is possible to pass an array of
	// select fields to load
	// Ensure the product is visible
	$products->addAttributeToFilter('visibility', array('neq' => 1));
	// Ensure the product is enabled
	$products->addAttributeToFilter('status', 1);
	// Add  attribute name 


	// Limit the collection to 1 result
	// Load the collection

Re: query all products that have the same custom attribute value



Thank you for this, the reason I need the product IDs is this.


I have 6000 products in my accounting database (attribute my_product_id )


These turn into 31,000 products which I need for my layered navigation (car parts: make(dropdown), model(dropdown), year(multi-select) - different cars use the exact same part, but are sold as separate parts). Too complex to use as configurable product (I think)


The inventory is stored in the cataloginventory_stock_item table and holds the magento product IDs


So I could potentially have 1 actual product  which displays as 10 different products on the website


So whenever a purchase is made, I want to write a script to search the whole product database for all products that share that attribute ID (my_product_id) and adjust their inventory accordingly



I will also write a script for updating inventory levels and price (a different thread on here) So if I have 5 qty of my_product_id, then the 10 products it will turn into will all have 5 qty when I import


Re: query all products that have the same custom attribute value

To query all products that have the same custom attribute value, you'll need to interact with your database's tables that store product information and attributes. The specific tables and structure will depend on the e-commerce platform or database schema you're using. However, I can provide you with a general outline of how the query might look using SQL:

Let's assume you have the following tables:

  • products: Contains product information, including product_id.
  • product_attributes: Contains product attributes, including product_id and custom_attribute.

Here's a basic SQL query to achieve your goal:

SELECT p.product_id
FROM products p
JOIN product_attributes pa ON p.product_id = pa.product_id
WHERE pa.custom_attribute = 'your_desired_value';

Explanation of the query:

  1. SELECT p.product_id: This selects the product_id from the products table.

  2. FROM products p: This specifies the products table and assigns it the alias p.

  3. JOIN product_attributes pa ON p.product_id = pa.product_id: This performs an inner join between the products and product_attributes tables based on the product_id column, linking the two tables together.

  4. WHERE pa.custom_attribute = 'your_desired_value': This filters the results to only include rows where the custom_attribute in the product_attributes table matches the value you're interested in.

Replace 'your_desired_value' with the actual value you want to search for in the custom_attribute field.

Please note that the actual table and column names in your database might differ from the examples provided Meguiar’s here. You'll need to adjust the query to match your database schema. Also, if you're using a specific e-commerce platform, it might provide its own query builder tools or APIs to fetch this information more easily. Always refer to the documentation of your platform for the most accurate and relevant instructions.

Re: query all products that have the same custom attribute value

  • To query all products with the same custom attribute value, you'll first need to identify the attribute in question, much like you'd specify a destination when searching for tours.

  • Use SQL queries or relevant API calls to filter products based on this attribute. For example, in SQL it would be something like SELECT * FROM Products WHERE custom_attribute = 'value';.

  • If you're using an e-commerce platform like Shopify or Magento, look for built-in tools or plugins that allow custom attribute filtering. It's like using a specialized search engine for finding specific tour.

  • Once you've identified the products, you may want to sort or further filter them based on other parameters like price, ratings, or availability—similar to how you'd sort tour options based on reviews or durations.

  • Finally, take action based on your query results. This could mean updating those products, deleting them, or perhaps running special promotions, much like how you'd book a tour after finding the perfect match.

By following these steps, you can efficiently query all products with the same custom attribute value, just like how you'd find the perfect tour to match your travel criteria.

Re: query all products that have the same custom attribute value

Certainly, here are some points to query all products that have the same custom attribute value, using "security guards" as an example:

  1. Utilize your e-commerce or product database management system to access product data.
  2. Identify the specific custom attribute related to "security guards" or any other term you're interested in.
  3. Query the database to search for all products where this custom attribute has the desired value.
  4. Retrieve and list all the products that match the specified attribute value, which in this case could include items like security guard uniforms, security guard equipment, or security guard services.
  5. Make sure to customize your query and attribute value based on your specific product database and requirements.

Re: query all products that have the same custom attribute value

Querying Custom Attribute Value: Utilize the product database query system to identify all products sharing the same custom attribute value. Example with Merlin AI: Custom Attribute: "AI Integration" Value: "Merlin AI" Execute a query to retrieve all products featuring the custom attribute "AI Integration" with the value merlin AI. Detailed Steps: Access the product database management system. Define the specific custom attribute you want to query, such as "AI Integration." Specify the value associated with the custom attribute, in this case, "Merlin AI." Run the query to extract a list of all products that match the defined custom attribute and value. Review the results to identify products with the specified custom attribute value, in this example, those integrated with "Merlin AI." Merlin AI as an Illustration: Assume products like smart devices, software, or accessories have a custom attribute denoting AI compatibility. Products with the custom attribute "AI Integration" set to "Merlin AI" would be displayed, showcasing how this query method can be applied to filter and analyze relevant items within a diverse product range.