SQL get posts with taxonomy
SELECT DISTINCT ID
FROM( SELECT DISTINCT ID, post_type ,( SELECT group_concat(wp_terms.name separator ', ' )
FROM wp_terms
INNER JOIN wp_term_taxonomy
ON wp_terms.term_id = wp_term_taxonomy.term_id
INNER JOIN wp_term_relationships wpr
ON wpr.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
WHERE taxonomy = '$taxonomy'
AND wp_posts.ID = wpr.object_id
)
AS 'term'
FROM wp_posts
WHERE post_type = '$post_type'
)
AS x
WHERE term IS NOT NULL
ORDER BY ID ASC