SQLite

View Ticket
Login
2009-10-19
21:05 Fixed ticket [b73fb0bd64]: Natural self-join defect plus 2 other changes (artifact: 39153355fb user: drh)
19:47 Ticket [b73fb0bd64]: 3 changes (artifact: 1a3635f577 user: drh)
15:52
When generating WHERE clause terms internally for NATURAL and USING joins, identify the table by its position in the FROM list, not by its name or alias. Fix for [b73fb0bd64]. (check-in: 6fe6371175 user: dan tags: trunk)
2009-10-18
18:19 New ticket [b73fb0bd64] Natural self-join defect. (artifact: b9586609bb user: drh)

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]