Query SQL query

-2

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

I have two ads and likes tables; when a user likes an ad, a record is created in the likes table with the user id and ad id Enjoyed it.

You need to capture the most tanned ads. Someone has an idea. I'm using MySQL and PHP.

    
asked by anonymous 13.01.2016 / 19:17

1 answer

2

Just to complement and close your question I'm 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
    
17.01.2016 / 10:38