我正在尝试编写以下类似的查询
WITH a AS (SELECT key FROM table)
SELECT *
FROM a
JOIN b;
这段代码在PostgreSQL 10.4中会生成语法错误。
为什么会出现这个错误呢?
看起来我将创建一个视图来代替。是否有更好的解决方案?
我正在尝试编写以下类似的查询
WITH a AS (SELECT key FROM table)
SELECT *
FROM a
JOIN b;
你缺少了连接条件:
WITH a AS (SELECT key FROM table)
SELECT *
FROM a
JOIN b <b>ON a.key = b.key</b>;
SELECT *
FROM a
JOIN b
-- something missing here
JOIN
默认为内连接,需要一些条件来确定应该连接哪些行 - 通常是像ON a.key = b.key
或USING key
。对于LEFT OUTER JOIN
或RIGHT OUTER JOIN
也是如此。CROSS JOIN
:SELECT *
FROM a
CROSS JOIN b;
SELECT *
FROM a, b;
ON
或USING
。 - Laurenz Albe