Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango order_by causes LEFT JOIN
    text
    copied!<p>Can anyone tell me why when I add the <code>order_by()</code> the query that gets output changes from a <code>INNER JOIN</code> to an <code>LEFT OUTER JOIN</code>? </p> <p>Is there any way to preserve the <code>INNER JOIN</code>-ness?</p> <pre><code>data = models.RetailSalesFact.objects.values('customer_key__customer_state', 'date_key__calendar_month_name') data = data.filter(date_key__calendar_year=year) data = data.annotate(sales=Sum('sales_quantity')) data = data.order_by('date_key__calendar_month_name') </code></pre> <p><strong>Before:</strong></p> <pre><code>SELECT Customer_Dimension.Customer_State, Date_Dimension.Calendar_Month_Name, SUM(Retail_Sales_Fact.Sales_Quantity) AS sales FROM Retail_Sales_Fact INNER JOIN Customer_Dimension ON (Retail_Sales_Fact.Customer_Key = Customer_Dimension.Customer_Key) INNER JOIN Date_Dimension ON (Retail_Sales_Fact.Date_Key = Date_Dimension.Date_Key) WHERE Date_Dimension.Calendar_Year = ? GROUP BY Customer_Dimension.Customer_State, Date_Dimension.Calendar_Month_Name ORDER BY Date_Dimension.Calendar_Month_Name ASC </code></pre> <p><strong>After:</strong></p> <pre><code>SELECT Customer_Dimension.Customer_State, Date_Dimension.Calendar_Month_Name, SUM(Retail_Sales_Fact.Sales_Quantity) AS sales FROM Retail_Sales_Fact INNER JOIN Customer_Dimension ON (Retail_Sales_Fact.Customer_Key = Customer_Dimension.Customer_Key) LEFT OUTER JOIN Date_Dimension ON (Retail_Sales_Fact.Date_Key = Date_Dimension.Date_Key) WHERE Date_Dimension.Calendar_Year = ? GROUP BY Customer_Dimension.Customer_State, Date_Dimension.Calendar_Month_Name ORDER BY Date_Dimension.Calendar_Month_Name ASC </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