在这个例子中,我们在SQLite数据库上有3个相关的表:
CREATE TABLE test1 (
c1 integer,
primary key (c1)
);
CREATE TABLE test2 (
c1 integer,
c2 integer,
primary key (c1, c2)
);
CREATE TABLE test3 (
c2 integer,
c3 integer,
primary key (c2)
);
现在我需要加入所有表格:
test1 -> test2 (with c1 column) test2 -> test3 (with c2 column).
我试过这个解决方案,但它没有运行:
SELECT
*
FROM test1 a
LEFT OUTER JOIN test2 b
LEFT OUTER JOIN test3 c
ON c.c2 = b.c2
ON b.c1=a.c1
它给了我一个错误:
near "ON": syntax error.
任何帮助?
答案 0 :(得分:31)
这是您ON
声明的简单错位。这符合SQL标准:
SELECT *
FROM test1 a
LEFT OUTER JOIN test2 b ON b.c1=a.c1
LEFT OUTER JOIN test3 c ON c.c2=b.c2
中对此进行了解释