我正在尝试根据它们的 id 生成行的成对组合。SQLite 版本是 3.5.9。表格内容如下:
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
这显然不是我想要的。现在,更改 t2 和 t1 的顺序会产生正确的结果:
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 的某些微妙方面。
谢谢,