title: Sequelize returns different value than MySql result
body: <p>I have something very odd happening and nothing seems to work. I have a SP in MySql that returns some results. When I run the SP in MySql workbench everything is correct. The query is quite long. But this is the LEFT JOIN is somehow creating the issues. I have other inner joins/left joins but they are fine.</p>
  <pre><code>SELECT DISTINCT Id.ReelTag
          , Id.ECSPartNo
          , WM.ShortDescription AS Description
          , Id.ReelTagSerial
          , group_concat(DISTINCT RA.UniqueID) AS UniqueID
          , group_concat(DISTINCT coalesce(RA.OrdNo, Std.OrdNo)) AS OrdNo
          , Id.Received
          , IFNULL(Std.ReelQuantity,0) AS OriginalQuantity
          , IFNULL(Id.Quantity,0) AS CurrentQuantity
          , IFNULL(yest.Quantity,0) AS YesterdayQuantity
          , IFNULL(cuts.Quantity,0) AS QuantityChanged
          , cuts.OrdNo AS OrdNoChange
          , IFNULL(CC.ShipQuantity,0) AS ShipQuantity
          , CC.OrdNo AS OrdNo_Allocated
          , IFNULL(Id.Quantity,0) - IFNULL(yest.Quantity,0) AS changeAOF_Yesterday
      FROM InventoryDtl Id .....
  
  LEFT JOIN (
          SELECT 
              SourceReel
              , SUM(CASE WHEN Action = 'Insert' THEN TotalQuantity
                      WHEN Action = 'Delete' THEN -TotalQuantity
                      ELSE 0 END) AS Quantity
              , group_concat(DISTINCT CASE WHEN Action = 'Insert' THEN concat(OrdNo,'(Cut)') ELSE concat(OrdNo,'(UnCut)') END) AS OrdNo
          FROM (
              SELECT 
                  Action
                  , SourceReel
                  , OrdNo
                  , SUM(Quantity) AS TotalQuantity
              FROM CableCuts_Log CD
              WHERE 1=1
              AND 1 = CASE
                  WHEN SourceReel IS NOT NULL AND OrdNo LIKE 'E9%' AND Quantity &gt; 0 AND DaTediff(Now(),LogDate) = 0 THEN 1
                  ELSE 0 END
              GROUP BY Action, SourceReel, OrdNo
          ) CC
          WHERE 1=1
          GROUP BY SourceReel
      ) cuts ON Id.ReelTag = cuts.SourceReel
  </code></pre>
  <p>Again, When I run this in MySql workbench it's fine and loads in a second if that makes a difference.</p>
  <p>But when I call my API to call the SP using ...</p>
  <pre><code>let inventoryReport = await models.sequelize
      .query(
          `call rpt_DailyInventoryReport($location, $byECSPartNo);`,
          { bind: {location: req.body.location, byECSPartNo: null} },           
      )
  
  for(i=0;i&lt;inventoryReport.length;i++) {
          if(inventoryReport[i].ReelTagSerial == '6906' || inventoryReport[i].ReelTagSerial == '6858') {
              console.log(inventoryReport[i]);
          }
          
      }
  </code></pre>
  <p>and exporting that into an Excel using ExcelJS, the 2 &quot;cuts&quot; columns from the query are essentially NULLs, because the return value of the &quot;cuts&quot; select are coming up NULLS, which is why  it's giving the IFNULL value instead. Again this work in MySql workbench.</p>
  <p>These are the values the API throws out.</p>
  <pre><code>{
              &quot;ReelTagSerial&quot;: 6858,
              &quot;CurrentQuantity&quot;: 700,
              &quot;YesterdayQuantity&quot;: 2500,
              &quot;QuantityChanged&quot;: 0,
              &quot;OrdNoChange&quot;: null,
              &quot;ShipQuantity&quot;: 0,
              &quot;OrdNo_Allocated&quot;: null,
              &quot;changeAOF_Yesterday&quot;: -1800
          },
  
  {
              &quot;ReelTagSerial&quot;: 6906,
              &quot;CurrentQuantity&quot;: 2730,
              &quot;YesterdayQuantity&quot;: 3330,
              &quot;QuantityChanged&quot;: 0,
              &quot;OrdNoChange&quot;: null,
              &quot;ShipQuantity&quot;: 0,
              &quot;OrdNo_Allocated&quot;: null,
              &quot;changeAOF_Yesterday&quot;: -600
          },
  </code></pre>
  <p>Here are the 2 rows that their values should be.</p>
  <pre><code>{
              &quot;ReelTagSerial&quot;: 6906,
              &quot;CurrentQuantity&quot;: 2730,
              &quot;YesterdayQuantity&quot;: 3330,
              &quot;QuantityChanged&quot;: 600,
              &quot;OrdNoChange&quot;: E92021(Cut),
              &quot;ShipQuantity&quot;: 0,
              &quot;OrdNo_Allocated&quot;: null,
              &quot;changeAOF_Yesterday&quot;: -600
          }
  
  {
              &quot;ReelTagSerial&quot;: 6858,
              &quot;CurrentQuantity&quot;: 700,
              &quot;YesterdayQuantity&quot;: 2500,
              &quot;QuantityChanged&quot;: 1800,
              &quot;OrdNoChange&quot;: E912345(Cut),
              &quot;ShipQuantity&quot;: 0,
              &quot;OrdNo_Allocated&quot;: null,
              &quot;changeAOF_Yesterday&quot;: -1800
          },
  </code></pre>
  <p>I have tried creating a temp table and defining the field type of varchar, text, mediumint for the QuantityChanged field.
  At first I thought maybe ExcelJs was not liking the key/value pairs but then I simply console logged the 2 rows and they are returning like that from Sequelize. I have tried casting the 2 fields with every datatype possible.</p>
  <pre><code>, CAST(cuts.OrdNo AS char) AS OrdNoChange
  , CAST(cuts.OrdNo AS binary) AS OrdNoChange
  </code></pre>
  <p>Now I am just immediately sending the return result as a response back to Postman and seeing all the rows to make sure for whatever reason those values are not being set in other rows. But they seem to be all good.</p>
  <p>If I simply rearrange the columns so that the two bad fields get values of other fields, they do populate with their values, so that's about as far as I got. Or if I put just 1000 or a string type it returns correctly, so IT MUST be something to do with those 2 data types from the &quot;cuts&quot; query.</p>
  <p>I have tried returning simply returning these from the &quot;cuts&quot; join query</p>
  <pre><code>SELECT 
              DISTINCT SourceReel
              #, CAST(SUM(CASE WHEN Action = 'Insert' THEN TotalQuantity
              #       WHEN Action = 'Delete' THEN -TotalQuantity
              #       ELSE 0 END) AS UnSigned) AS Quantity
              , SUM(TotalQuantity) AS Quantity
              ,  OrdNo
              #, group_concat(DISTINCT CASE WHEN Action = 'Insert' THEN concat(OrdNo,'(Cut)') ELSE concat(OrdNo,'(UnCut)') END) AS OrdNo
  </code></pre>
  <p>Nothing is working. Spent hours troubleshooting and searching...</p>
  <p>Need some help please :)</p>
  <p>Thanks in advance.</p>