<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SQL triple joins, or how to distinctly combine order details in SQL database</title>
    <link>https://community.fabric.microsoft.com/t5/SQL-database/SQL-triple-joins-or-how-to-distinctly-combine-order-details/m-p/4300850#M27</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="860671" data-lia-user-login="EHaft" class="lia-mention lia-mention-user"&gt;EHaft&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may try:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;SELECT 
Orders.OrderID, SUM(Sales.QuantitySold*Products.SellPrice) AS 'Total Price'
FROM Sales
LEFT JOIN Orders ON Orders.OrderID = Sales.OrderID
LEFT JOIN Products ON Products.ProductName = Sales.ProductSold
GROUP BY Orders.OrderID&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this statement doesn't work on your end, could you please provide us with the table creation statement and sample data, as well as your expect result?&lt;/P&gt;
&lt;P&gt;Note:Please be careful not to include sensitive information)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards.&lt;BR /&gt;Community Support Team_Caitlyn&lt;/P&gt;</description>
    <pubDate>Tue, 26 Nov 2024 02:07:45 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-11-26T02:07:45Z</dc:date>
    <item>
      <title>SQL triple joins, or how to distinctly combine order details</title>
      <link>https://community.fabric.microsoft.com/t5/SQL-database/SQL-triple-joins-or-how-to-distinctly-combine-order-details/m-p/4300676#M25</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having some trouble attempting to return the total price for each order placed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working with the following tables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Orders (OrderID, OrderDate, Location)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sales (OrderID, ProductSold, QuantitySold)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Products (ProductName, SellPrice)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to distinctly select all unique Orders.OrderID entries, and tabulate the sum of each product sold per order.&lt;/P&gt;&lt;P&gt;My problem is that all values in Orders.OrderID are distinct (e.g. 1-20), but for Sales.OrderID there are multiple values per ID (Sales contains the OrderID in question, what product was sold, and how many; thus there may be multiple products [sales] per one order [orders].&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a simple solution for this that I'm missing?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I've got so far:&lt;/P&gt;&lt;P&gt;SELECT DISTINCT&lt;BR /&gt;Orders.OrderID, Sales.ProductSold, Sales.QuantitySold*Products.SellPrice AS 'Total Price'&lt;BR /&gt;FROM Sales&lt;BR /&gt;LEFT JOIN Orders ON Orders.OrderID = Sales.OrderID&lt;BR /&gt;LEFT JOIN Products ON Products.ProductName = Sales.ProductSold;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This returns multiple 'Total Prices' per 'ProductSold" for each OrderID.&lt;/P&gt;&lt;P&gt;Would there be a method way to sum 'Total Price' for each unique OrderID rather than for each ProductSold?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Otherwise:&lt;/P&gt;&lt;P&gt;Is there a way to combine the ProductSold and QuantitySold for each order, while still maintaining references to their respective ProductName and SellPrice? Is there a way to combine the information specific to each unique ID number or a way to concatanate all that information into a new table using SQL alone?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Simply put, I'd like this query to return 20 records describing complete orders rather than 60 records describing each piece of an order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help with this, I appreciate you!&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2024 23:23:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/SQL-database/SQL-triple-joins-or-how-to-distinctly-combine-order-details/m-p/4300676#M25</guid>
      <dc:creator>EHaft</dc:creator>
      <dc:date>2024-11-25T23:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: SQL triple joins, or how to distinctly combine order details</title>
      <link>https://community.fabric.microsoft.com/t5/SQL-database/SQL-triple-joins-or-how-to-distinctly-combine-order-details/m-p/4300850#M27</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="860671" data-lia-user-login="EHaft" class="lia-mention lia-mention-user"&gt;EHaft&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may try:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;SELECT 
Orders.OrderID, SUM(Sales.QuantitySold*Products.SellPrice) AS 'Total Price'
FROM Sales
LEFT JOIN Orders ON Orders.OrderID = Sales.OrderID
LEFT JOIN Products ON Products.ProductName = Sales.ProductSold
GROUP BY Orders.OrderID&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this statement doesn't work on your end, could you please provide us with the table creation statement and sample data, as well as your expect result?&lt;/P&gt;
&lt;P&gt;Note:Please be careful not to include sensitive information)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards.&lt;BR /&gt;Community Support Team_Caitlyn&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2024 02:07:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/SQL-database/SQL-triple-joins-or-how-to-distinctly-combine-order-details/m-p/4300850#M27</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-26T02:07:45Z</dc:date>
    </item>
  </channel>
</rss>

