Can someone please explain me this SQL query. This shows me the popular stores, but it doesn’t works well.
sql = "SELECT t.name, t.slug, tt.count
FROM ".$wpdb->prefix."terms AS t INNER JOIN ".$wpdb->prefix."term_taxonomy AS tt ON t.term_id = tt.term_id
WHERE
tt.taxonomy IN ('$tax_name')
AND tt.count > 0
GROUP BY tt.count DESC
ORDER BY RAND() LIMIT $the_limit";
For
GROUP BYto work, you need to apply some kind of aggregating function to everything you’re notGROUPingBY.I assume what you want is the total count for each store: