You can use the sentence where id is nullto require that it left joinfail:
SELECT p.*
FROM wp_posts p
LEFT JOIN
wp_term_relationships rel
ON p.ID = rel.object_id
LEFT JOIN
wp_term_taxonomy tax
ON tax.term_taxonomy_id = rel.term_taxonomy_id
AND tax.taxonomy = 'category'
LEFT JOIN
wp_terms term
ON term.term_id = tax.term_id
WHERE p.post_type = 'post'
AND p.post_status = 'publish'
AND term.term_id is null
SentenceA not existcan be performed:
SELECT *
FROM wp_posts p
WHERE p.post_type = 'post'
AND p.post_status = 'publish'
AND NOT EXISTS
(
SELECT *
FROM wp_term_relationships rel
JOIN wp_term_taxonomy tax
ON tax.term_taxonomy_id = rel.term_taxonomy_id
AND tax.taxonomy = 'category'
JOIN wp_terms term
ON term.term_id = tax.term_id
WHERE p.ID = rel.object_id
)
source
share