Q&A about the site for Drupal developers and administrators
with pt as ( select pt.tagid, pt.postid, t.tagname from posttags pt join tags t on pt.tagid = t.id ) select pt.tagname, pt2.tagname, count(*) from pt join pt pt2 on pt.postid = pt2.postid and pt.tagname < pt2.tagname group by pt.tagname, pt2.tagname order by count(*) desc;