• You're still missing DDL for tables and indexes.

    Things might speed up if you remove the ORDER BY and change your WHERE clause to

    WHERE A.entitlement_function NOT LIKE '@@@%'

    However, more improvements can be made with some changes to the DB (and possibly the code to remove the self join but I'm not sure). I'm sure that others will give better advices.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2