Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Very curious problem. When I drop 'Country' it seems to solve the issue.</p> <pre><code>SELECT DISTINCT PostalCode, City, Region </code></pre> <p><em>128 total, Query took 0.0066 sec</em></p> <pre><code>SELECT DISTINCT PostalCode, City, Region, Country </code></pre> <p><em>209 total, Query took 0.0002 sec</em></p> <p>Further, the behavior seems to only be affecting <code>ImportCustomers</code> and <code>ImportOrders</code>:</p> <pre><code>SELECT postalcode, city, region, country FROM (SELECT postalcode, city, region, country FROM importcustomers UNION SELECT shippostalcode, shipcity, shipregion, shipcountry FROM importorders) t </code></pre> <p><em>172 total, Query took 0.0053 sec</em></p> <pre><code>SELECT postalcode FROM (SELECT postalcode FROM importcustomers UNION SELECT shippostalcode FROM importorders) t </code></pre> <p><em>91 total, Query took 0.0050 sec</em></p> <p>I then narrowed it to the <code>country</code> column on <code>importcusotmers</code> and <code>importorders</code></p> <pre><code>SELECT TRIM(country) AS country FROM importcustomers UNION SELECT TRIM(shipcountry) AS country FROM importorders </code></pre> <pre>Argentina Argentina Austria Austria Belgium Belgium ...</pre> <p>Something interesting happened when I cast the column to <code>BINARY</code></p> <pre><code>SELECT BINARY country AS country FROM importcustomers UNION SELECT BINARY shipcountry AS country FROM importorders </code></pre> <pre>Argentina 417267656e74696e610d Austria 417573747269610d Belgium 42656c6769756d0d ...</pre> <p>The table <code>ImportOrders</code> is causing the duplicates.</p> <pre><code> SELECT BINARY shipcountry AS country FROM importorders </code></pre> <pre>4765726d616e790d 5553410d 5553410d 4765726d616e790d ...</pre> <p>Looking at the dump you provided, there is an extra <code>\r</code> (represented by <code>0d</code> in the values) appended to the end of the country.</p> <pre>-- -- Dumping data for table `importorders` -- INSERT INTO `importorders` VALUES ...'Germany\r'), ...'USA\r'), ...'USA\r'), ...'Germany\r'), ...'Mexico\r'), </pre> <p>Where in <code>importcustomers</code> the <code>country</code> looks fine:</p> <pre>-- -- Dumping data for table `importcustomers` -- INSERT INTO `importcustomers` VALUES ...'Germany', ... , ...'Mexico', ... , ...'Mexico', ... , ...'UK', ... , ...'Sweden', ... ,</pre> <p>You can remove these <code>\r</code>'s (carriage returns) by running this query:</p> <pre><code>UPDATE importorders SET ShipCountry = REPLACE(ShipCountry, '\r', '') </code></pre> <p>You will then get the desired result set if you run your original query. FYI, you do not need the <code>DISTINCT</code> if you are using <code>UNION</code>.</p> <pre><code>SELECT PostalCode, City, Region, Country FROM (SELECT postalcode, city, region, country FROM importemployees UNION SELECT postalcode, city, region, country FROM importcustomers UNION SELECT postalcode, city, region, country FROM importproducts UNION SELECT shippostalcode as postalcode, shipcity as city, shipregion as region, shipcountry as country FROM importorders) T </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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