For example, I have 3 tables: user
, group
and permission
, and two many2many relationships between them: user_groups
and <
Use EXISTS Rather than DISTINCT
You can suppress the display of duplicate rows using DISTINCT; you use EXISTS to check for the existence of rows returned by a subquery. Whenever possible, you should use EXISTS rather than DISTINCT because DISTINCT sorts the retrieved rows before suppressing the duplicate rows.
in your case there whould be many duplicated data so the exists should be faster.
by http://my.safaribooksonline.com/book/-/9780072229813/high-performance-sql-tuning/ch16lev1sec10