0

i need make a join costum tables in my query. I need to do a cycle of all products ordered by categories of "entity_id" and join this select if is valid

SELECT *, pps_product_id, MIN(pps_last_unit_price) AS pps_last_unit_price, pps_quantity_product FROM ".Mage::getSingleton('core/resource')->getTableName('purchase_product_supplier')." WHERE pps_last_unit_price > '0' AND pps_last_unit_price != '' AND pps_product_id = ".$data['entity_id']." GROUP BY pps_product_id 

and join with SELECT *, COUNT(entity_id) AS conta FROM ".Mage::getSingleton('core/resource')->getTableName('catalog_category_entity_varchar')." WHERE attribute_id = 192 AND entity_id = ".$IDProduto." AND value != '' AND value != '0' if is valid. Anybody can help me? Thanks

2 Answers 2

3

why not:

$orders->getSelect()->join( array('p' => $orders->getResource()->getTable('sales/order_payment')), 'p.parent_id = main_table.entity_id', array('cc_last4' => 'p.cc_last4', 'cc_type' => 'p.cc_type', 'additional_information' => 'p.additional_information', ) ); 
Sign up to request clarification or add additional context in comments.

Comments

1

First of all, generally it is preferred within Magento to use the Magento Models for querying the database. That way your queries will also work on other Databases if you decide to switch (currently unsupported as far as I know, but still its worth it).

I like to use this link or this one for figuring out joins.

Your question is very vague. Can you provide the schema of the custom table? What is being joined with what? On what fields?

To start, I'd say it'll look something like this:

$pps = Mage::getModel('purchase_product_supplier')->getCollection() ->addAttributeToFilter('pps_last_unit_price', array('gt' => 0)) ->addAttributeToFilter('pps_last_unit_price', true) ->addAttributeToFilter('pps_product_id', $data['entity_id']); $pps->getSelect()->join( ); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.