SQLite

Ticket Change Details
Login
Overview

Artifact ID: 4685201918074276438405d46331432d6c96bfd5
Ticket: d06a25c84454a372be4e4c970c3c4d4363197219
Incorrect result from a UNION with an ORDER BY
User & Date: drh 2016-02-08 22:22:47
Changes

  1. foundin changed to: "3.10.2"
  2. icomment:
    The following SQL code generates an incorrect answer of three rows instead of two:
    
    <blockquote><verbatim>
    CREATE TABLE tx(id INTEGER PRIMARY KEY, a, b);
    INSERT INTO tx(a,b) VALUES(33,456);
    INSERT INTO tx(a,b) VALUES(33,789);
    
    SELECT DISTINCT t0.id, t0.a, t0.b
      FROM tx AS t0, tx AS t1
     WHERE t0.a=t1.a AND t1.a=33 AND t0.b=456
    UNION
    SELECT DISTINCT t0.id, t0.a, t0.b
      FROM tx AS t0, tx AS t1
     WHERE t0.a=t1.a AND t1.a=33 AND t0.b=789
     ORDER BY 1;
    </verbatim></blockquote>
    
    Prior to and including check-in [93121d3097a43997] (version 3.8.3, 2013-12-17) 
    the correct answer was obtained.  After that, the test script above generates
    an assertion fault.  At check-in [c0fa0c0e2de50d7e] (version 3.8.4, 2014-03-03)
    the assertion faults go away, but the incorrect answer is returned.
    
  3. login: "drh"
  4. mimetype: "text/x-fossil-wiki"
  5. severity changed to: "Severe"
  6. status changed to: "Open"
  7. title changed to: "Incorrect result from a UNION with an ORDER BY"
  8. type changed to: "Code_Defect"