SELECT distinct p.ID id
FROM yadata_posts p
JOIN yadata_postmeta meta0 ON p.ID = meta0.post_id AND meta0.meta_key = 'is_active'
JOIN yadata_postmeta meta_order ON p.ID = meta_order.post_id AND meta_order.meta_key = 'associate_details_last_name'
WHERE
p.post_status = 'publish'
AND (meta0.meta_value = 'TRUE' or meta0.meta_value = '1')
AND p.post_type = 'associates' order by p.post_title asc