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'
JOIN yadata_postmeta meta1 ON p.ID = meta1.post_id AND meta1.meta_key = 'associate_details_department'
WHERE
p.post_status = 'publish'
AND (meta0.meta_value = 'TRUE' or meta0.meta_value = '1')
AND meta1.meta_value = 'Accident Reconstruction & Forensic Animation'
AND p.post_type = 'associates' order by p.post_title asc