I have a query which returns all PM's in the Trash Folder.

It is a UNION of Query #1 which returns "Deleted Incoming" messages, and Query #2 which returns "Deleted Sent" messages.

In Query #1, I have a column/alias called..
Code:
r.recipient_read_on AS read_on
In Query #2, there is no concept of a "Read Sent Message", so I stubbed it out like this...
Code:
-1 AS read_on
When I run the UNION Query, everything works great, but here is the catch...

Now I want to filter the record-set on whether there is a "-1" for "read_on" - which would tell me if it is a "Sent Message", but apparently I cannot use an Alias in the WHERE statement.


This fails...
Code:
WHERE pm.id = 90
AND pm.sender_id = 11
AND pm.sender_deleted_on IS NOT NULL
AND pm.sender_purged_on IS NULL
AND read_on = -1
How can I fix this issue?

Sincerely,


Debbie