title: Exporting order details magento
body: <p>I am looking to export order information for all the orders from a magento system i want to migrate from. 
  These are the fields I require</p>
  
  <pre><code>Order_id, sku, item_quantity, item_price, order_total_amount,  Created_at, Billing_address, Billing_city, billing_state, billing_country, billing_zipcode, billing_customer_name, billing_customer_mobile, billing_customer_email, shipping_address, shipping_city, Shipping_state, shipping_zipcode, Shipping_country, shipping_charge, shipping_customer_name, shipping_customer_mobile, order_status
  </code></pre>
  
  <p>I have tried a few free extensions but they do not solve my purpose. </p>
  
  <p>It would be helpful if you can help me write a SQL to export the data out.</p>
  
  <p>I already have a SQL. Could you help me refine this to get the details i need</p>
  
  <pre><code>SELECT sfo.entity_id, sfo.status, sfo.customer_email, oi.product_id, oi.name, 
  oi.price, sfo.total_due, billing.firstname, billing.lastname, billing.street,
  billing.city, billing.postcode, billing.country_id, billing.telephone, shipping.firstname,
  shipping.lastname, shipping.street, shipping.city, shipping.postcode, shipping.country_id,
  shipping.telephone, sfo.store_name, sfo.store_currency_code, sfo.created_at
  FROM sales_flat_order AS sfo
  JOIN sales_flat_order_address AS billing ON billing.parent_id=sfo.entity_id AND billing.address_type='billing'
  JOIN sales_flat_order_address AS shipping ON shipping.parent_id=sfo.entity_id AND shipping.address_type='shipping'
  JOIN sales_flat_order_item as oi ON oi.order_id=sfo.entity_id
  </code></pre>
  
  <p>I also need to handle the case where one order can include multiple items.</p>