Q&A for professional and amateur woodworkers
SELECT COALESCE((SELECT vttps.Name FROM VoteTypes vttps WHERE vttps.id=resQ.VoteTypeId), 'N/A') as VoteTypeName ,resQ.Counter as UniquePosts FROM ( SELECT vts.VoteTypeId ,COUNT(DISTINCT pst.id) as Counter FROM Posts pst Left Join Votes vts ON vts.postId=pst.id GROUP BY vts.VoteTypeId) as resQ ORDER BY 2 DESC ;