我試圖根據它們的id生成行的成對組合。 SQLite版本是3.5.9。該表內容如下:SQLite自加入ID的錯誤?
id|name|val
1|A|20
2|B|21
3|C|22
與表模式之中:
CREATE TABLE mytable (
id INTEGER NOT NULL,
name VARCHAR,
val INTEGER,
PRIMARY KEY (id)
);
再有就是對IDS自聯接:
sqlite> select t1.id, t2.id from mytable as t1, mytable as t2 where t2.id > t1.id;
id|id
2|2
2|3
3|3
這顯然不是我想要的。現在,改變T1和T2的順序產生正確的結果:
sqlite> select t1.id, t2.id from mytable as t2, mytable as t1 where t2.id > t1.id;
id|id
1|2
1|3
2|3
現在,另一個實驗中,我試圖在比行ID等數字列組合。另一方面,在這兩種情況下都會給出正確的結果。
我希望有人能夠洞察一下這裏發生了什麼。據我所知,它不是SQLite中的一個錯誤,就是SQL的一些微妙方面,我不知道。
感謝,
通過python確認sqlite 3.3.14中第一個查詢的正確結果。 – 2008-11-20 02:13:52