SELECT
(SELECT COUNT(*) FROM votes WHERE votes.vote = 1) AS upvotes,
(SELECT COUNT(*) FROM votes WHERE votes.vote = -1) AS downvotes,
FROM votes WHERE link = <linkid>
Straight up question; how could this be optimized? I can’t think of any better way to do it but I’m bad at MySQL.
Thanks for any responses!
EDIT: To make things clear: I want it to return one row with two columns; upvotes and downvotes
Try using SUM instead of COUNT:
Note that this does not give you the same result as the query you posted. I think the query you posted is wrong!