Subject Setting the filter for an IBOQuery for an aliased field
Author Raymond Kennington
The query is:

SELECT ID, Name, Sex, "Sire ID" AS ParentID FROM Animal A1
WHERE Sex = 'M'
AND NOT EXISTS (SELECT "Sire ID" FROM Animal A2 WHERE A2."Sire ID" = A1.ID)
UNION
SELECT ID, Name, Sex, "Dam ID" AS PreantID FROM Animal A1
WHERE Sex = 'F'
AND NOT EXISTS (SELECT "Dam ID" FROM Animal A2 WHERE A2."Dam ID" = A1.ID)

The Filter is:
ParentID=1

The field ParentID is not recognised.

Must I write the query as:

SELECT ID, Name, Sex, ParentID FROM
(
SELECT ID, Name, Sex, "Sire ID" AS ParentID FROM Animal A1
WHERE Sex = 'M'
AND NOT EXISTS (SELECT "Sire ID" FROM Animal A2 WHERE A2."Sire ID" = A1.ID)
UNION
SELECT ID, Name, Sex, "Dam ID" AS PreantID FROM Animal A1
WHERE Sex = 'F'
AND NOT EXISTS (SELECT "Dam ID" FROM Animal A2 WHERE A2."Dam ID" = A1.ID)
)

in order to have IBOQuery handle the filter correctly?

TIA.
Raymnd.
--
Raymond Kennington
Programming Solutions
W2W Team B