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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:10:45+00:00 2026-06-07T05:10:45+00:00

I was wondering how you can select columns. Above you can see the sql

  • 0

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.

I tried to add ->columns(‘o.sku AS SKU’) but this didn’t work.

Any ideas? Thanks in advance!

//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->getConnection('core_read');
$o = $resource->getTableName('magento_sales_flat_order');
$o_item = $resource->getTableName('magento_sales_flat_order_item');
$o_address = $resource->getTableName('magento_sales_flat_order_address');
$select = $read->select()->from(array('c'=>$o))
    ->join(array('o'=>$o_item), 'c.entity_id = o.order_id', array(o.sku AS  'SKU'))
    ->join(array('a'=>$o_address), 'a.parent_id = c.entity_id', array())
    ->where('o.product_id', $product)
    ->group('c.entity_id')
    ->order('o.sku');
  • 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-06-07T05:10:48+00:00Added an answer on June 7, 2026 at 5:10 am

    You souldn’t work like this with core modules at all. Those low level SQL queries should be used by resource models only. Especially not within a controller.

    You should get an instance of Mage_Sales_Model_Resource_Order_Collection by calling Mage::getModel('sales/order')->getCollection() and build your query from there. Just have a look at the source code to find out about how to do that exactly; start at app/code/core/Mage/Sales/Model/Resource/Order/Collection.php and work your way down the inheritance chain.

    For example, you can add a WHERE using something like $collection->addAttributeToSearchFilter().

    Magento’s got great database abstraction and you sould definately be using it.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wondering how can I select columns with specific collation. For example, I want
I was wondering how I can select the output device for audio in directshow.
i was wondering if jquery can be used to manipulate my select html element
I was just wondering if you can do something like this List<string> maincolumns =
Is there a better way of doing a query like this: SELECT COUNT(*) FROM
was wondering how can I create a sub drop down box upon selecting a
I was wondering how can I track the current logged in user in a
I was wondering how can I control the image on the connect dialog? I
i'm wondering how can I compare in C language, a number I put on
I was wondering how can I do something similar to Facebook when a link

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.