SQLite

View Ticket
Login
Ticket Hash: b73fb0bd649311d133a9511b1c368d642784cfab
Title: Natural self-join defect
Status: Fixed Type: Code_Defect
Severity: Important Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2009-10-19 21:05:11
15.71 years ago
Created: 2009-10-18 18:19:51
15.71 years ago
Version Found In: 3.6.19
Description:
The following SQL does not generate the correct result:
   CREATE TABLE t1(
     a INTEGER PRIMARY KEY,
     b TEXT
   );
   INSERT INTO t1 VALUES(1,'abc');
   INSERT INTO t1 VALUES(2,'def');
   SELECT * FROM t1 NATURAL JOIN t1;

A simple work-around is to alias one or both of the tables being joined. For example

   SELECT * FROM t1 a NATURAL JOIN t1;
   SELECT * FROM t1 NATURAL JOIN t1 b;
   SELECT * FROM t1 a NATURAL JOIN t1 b;

This problem appears to originate in version 3.2.2 on 2005-06-13.


drh added on 2009-10-19 21:05:11:
See check-in [6fe6371175482d38ac4aeea994c7b20c18b7de01]