Q:

SQL - fetch images with count likes, and count my likes on them

I'm stuck in a query to fetch images, with count likes on them, but also my likes on each images, my actual query is :
SELECT images.idimage, count( likes.idlike ) likes, count( likes2.idlike ) mylikes
FROM images
LEFT JOIN likes ON images.idimage = likes.idimage
LEFT JOIN likes likes2 ON images.idimage = likes2.idimage AND likes2.iduser =3
GROUP BY images.idimage

But it seems not working, column mylikes return me total likes of image, not only mine.
Any help on that?
Thanks

A:

You can do also this way 

SELECT images.idimage, count( *  ), sum(case when iduser=3 then  1 else 0 end) as mylikes
FROM images
LEFT JOIN likes ON images.idimage = likes.idimage
GROUP BY images.idimage

