Test suite (as simple as I can produce):
CREATE TABLE foo (a int, b int);
INSERT INTO foo VALUES (1,2);
INSERT INTO foo VALUES (2,3);
INSERT INTO foo VALUES (3,3);
CREATE VIEW fooview AS
SELECT
f1.a AS a_for_max_b
FROM
( SELECT MAX(foo.b) AS MaxB FROM foo ) f2
INNER JOIN foo f1
ON f2.MaxB = f1.b;
And this query fails:
SELECT
*
FROM
fooview fv1
LEFT OUTER JOIN fooview fv2
ON TRUE = TRUE;
It also fails with RIGHT join, but it doesn't fail with INNER or FULL joins.
If view is defined (essentially the same) as
CREATE VIEW fooview AS
SELECT
f1.a AS a_for_max_b
FROM
foo f1
WHERE
f1.b = (SELECT MAX(f2.b) FROM foo f2);
then all is ok.
--
Teodor Sigaev E-mail: teodor@sigaev.ru
WWW: http://www.sigaev.ru/