I would be surprised if UNION ALL gives better performance than a simple "OR" query, since it's effectively 2 queries and a merge, but some EXPLAIN analysis could confirm.

The '?' on what was supposed to be raw SQL threw me too. But I think I recall that using ? with LIKE-style operations gave me problems. Like whether to put the '%' on the SQL or in the value to be substituted.

For example, particularly in this case speakerid5 and lisenerid5 are grouped by appointmentid which it is also 5 in my mock database. So the undesired result I am gettting is two rows (one comin from each select) instad of just the newest one.