As a relatively new user of Magento and an even newer user of SQL, this question could be a dumb one.
I'm simply having a very hard time formulating an SQL query with the Magento API. The query I'm attempting to translate into the API is right below.
SELECT b.product_id, e.item_nr
FROM mag1catalog_product_flat_1 AS 'e'
RIGHT OUTER JOIN
mag1personal_order AS 'b'
ON b.product_id = e.item_nr
WHERE e.item_nr is null or e.erp_item_nr = '';
What I have so far in terms of a Magento collection query and the resulting SQL is below.
public function importCatalog() {
$catalogCollect = Mage::getModel('catalog/product')->getCollection();
$catalogCollect->addAttributeToFilter('item_nr');
$orderflyCollect->addAttributeToFilter('b.product_id');
$catalogCollect->getSelect()->joinRight(array('b'=>'mag1personal_order'), 'b.product_id = e.item_nr', 'e.item_nr');
echo $catalogCollect->getSelect();
SQL Query:
SELECT 1 AS `status`, `e`.`entity_id`, `e`.`type_id`, `e`.`attribute_set_id`, `e`.`item_nr`, `e`.`item_nr` FROM `mag1catalog_product_flat_1` AS `e` RIGHT JOIN `mag1personal_order` AS `b` ON b.product_id = e.item_nr WHERE (e.item_nr = '')
I have a few questions below.
1) Where is "1 AS" at the beginning of the SQL query coming from and how do I get it to leave?
2) Where did status
, e
.entity_id
, e
.type_id
, e
.attribute_set_id
, e
.item_nr
, and e
.item_nr
come from? I thought I tried to filter just e
.item_nr
and 'b.product_id'? 'b.product_id' isn't even there.
3) How does one specify a RIGHT/LEFT OUTER/INNER JOIN and not just a RIGHT/LEFT JOIN?
Any help with these would be greatly appreciated.