SELECT COALESCE((SELECT vttps.Name FROM VoteTypes vttps W...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Woodworking

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
;

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results