Doubt SQL query

Asked

Viewed 62 times

-2

I need to make a Mysql query in the following situation:

I have two tables announcements and Likes, when the user likes an ad a record is created in the Likes table with the user id and the ad id he likes.

And I need to capture the coolest ads. Someone has an idea. I’m using Mysql and PHP.

1 answer

2


Just to supplement and close your question I am reinserting your answer here:

Solution

SELECT 
    COUNT(*) as total_de_likes, 
    likes_anuncios.* 
FROM 
    likes_anuncios 
GROUP BY 
    anuncio_id 
ORDER BY 
    total_de_likes DESC

Browser other questions tagged

You are not signed in. Login or sign up in order to post.