I've got this query:
select p.ID, p.post_title, p.post_content, t.term_id, tt.taxonomy, t.name, t.slug, tt.count from bdu_posts p inner join bdu_term_relationships rel on p.ID = rel.object_id inner join bdu_term_taxonomy tt on tt.term_taxonomy_id = rel.term_taxonomy_id inner join bdu_terms t on tt.term_id = t.term_id where p.post_type = "prodotto" and p.post_status = "publish"
then, basically, I need the same results grouped by t.term_id. Or, better, a subset of columns of the first query's results (the ones term-related), grouped by t.term_id.
In theory, what I want is simply to use the first query results as a base "table" for another query to get other sub-results.
I'm not really good in SQL. Probably the way would be things like table views, but I'm not sure how they work and especially how to use them with $wpdb.
Does anyone know? :)