Note that there are some explanatory texts on larger screens.

plurals
  1. POselect column magento
    text
    copied!<p>I was wondering how you can select columns. Above you can see the sql I wanna write in the controller. But I want to do this the wright way. Like other sql statements in magento.</p> <p>I tried to add ->columns('o.sku AS SKU') but this didn't work.</p> <p>Any ideas? Thanks in advance!</p> <pre><code>//sql $readresult="SELECT o.name AS 'Product', o.sku AS 'SKU', c.entity_id AS 'Order', c.customer_email AS 'Email', c.customer_firstname AS 'Voornaam', c.customer_lastname AS 'Achternaam', c.customer_middlename AS 'Tussenvoegsel', o.product_options AS 'Options', a.telephone AS 'Telefoon', a.postcode AS 'Postcode', a.street AS 'Street', a.city AS 'City', c.increment_id AS 'Bestelnr' FROM magento_sales_flat_order AS c INNER JOIN magento_sales_flat_order_item AS o ON c.entity_id = o.order_id INNER JOIN magento_sales_flat_order_address AS a ON a.parent_id = c.entity_id WHERE o.product_id =".$product." GROUP BY c.entity_id ORDER BY o.sku;"; //THE MAGENTO WAY! $resource = Mage::getSingleton('core/resource'); $read = $resource-&gt;getConnection('core_read'); $o = $resource-&gt;getTableName('magento_sales_flat_order'); $o_item = $resource-&gt;getTableName('magento_sales_flat_order_item'); $o_address = $resource-&gt;getTableName('magento_sales_flat_order_address'); $select = $read-&gt;select()-&gt;from(array('c'=&gt;$o)) -&gt;join(array('o'=&gt;$o_item), 'c.entity_id = o.order_id', array(o.sku AS 'SKU')) -&gt;join(array('a'=&gt;$o_address), 'a.parent_id = c.entity_id', array()) -&gt;where('o.product_id', $product) -&gt;group('c.entity_id') -&gt;order('o.sku'); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload