Subject Re: FB 2.1.3 - cannot order VIEW rows
Author Svein Erling
This is the shortest way I've found to reproduce incorrect ordering - the combination DISTINCT, LEFT JOIN and ordering only on fields in the RIGHT table seems to be all there is to it. I never thought it could be that simple to make Firebird produce incorrect ordering.

CREATE TABLE TEST_TABLE(MYFIELD INTEGER);

CREATE VIEW TEST_VIEW(MYFIELD1, MYFIELD2) AS
SELECT DISTINCT M.MYFIELD, S.MYFIELD
FROM TEST_TABLE M
LEFT JOIN TEST_TABLE S ON M.MYFIELD = S.MYFIELD;

COMMIT;

INSERT INTO TEST_TABLE VALUES (1);
INSERT INTO TEST_TABLE VALUES (2);

COMMIT;

SELECT * FROM TEST_VIEW
ORDER BY MYFIELD1 DESC

HTH,
Set