Commerce: What field to join line_item in order to get product price in custom query? I'm starting with line 'commerce_line_item' as a base table, and I want to get prices for each of the line item products attached to a Drupal Commerce Order, rather than just the order total. I need a listing of each product sold with prices, and neither views nor Entity Field Query offer enough options for me (I'm creating a master order statistics spreadsheet with phpexcel).

The only promising field I have in the 'commerce_line_item' table is an 'order_id', which I can't find a way to relate back to 'commerce_product' and a 'line_item_label', which does not join on the field 'commerce_product.sku'. 

So what would I join on to get pricing information? 

I asked a similar question here, but this has me slightly more baffled.

Here's my code below for the query.

  $query = db_select('commerce_line_item', 'i');
  $query-&gt;fields('i', array('line_item_label', 'line_item_id', 'quantity', 'data'));
  $query-&gt;condition('i.type', 'product', '=');
  $query-&gt;leftjoin('commerce_product', 'cp', 'cp.sku = i.line_item_label');
  $query-&gt;leftjoin('field_data_commerce_price', 'fcp', 'fcp.entity_id = cp.product_id');
  $query-&gt;fields('fcp', array('commerce_price_amount'));
  $query-&gt;leftjoin('commerce_order', 'o', 'o.order_id = i.order_id');


snip->

Thanks for your help!
As you can see in the graph from the question you're linking, there's a field that relates the line item with the products, that's not a database field but a Drupal field. This means that there will be a database table for the field data and revisions and you don't want to deal with that in a db_query, you should be using Entity Field Query instead that will know the database tables and fields to use in each case.

I'm guessing you want to get products from the line items you already have, or the order.

I'd get the line items with EntityFieldQuery:

$query = new EntityFieldQuery();
$result = $query
  -&gt;entityCondition('entity_type', 'commerce_line_item')
  -&gt;propertyCondition('order_id', &lt;-your-order-id-&gt;)
  -&gt;execute();


Now you've got the line items there, wrap them and get the product price:

if (!empty($result['commerce_line_item'])) {
  foreach ($result['commerce_line_item'] as $id =&gt; $value) {
    $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $id);
    $product_wrapper = $line_item_wrapper-&gt;commerce_product;
    $price = commerce_price_wrapper_value($product_wrapper, 'commerce_price', TRUE);
  }
}


Also, all this data is exposed to views, so you can create a view instead.