0

Hi I'm creating a website that uses a count query, to see how many things in the database match a variable.
Table eg:

Whats Liked User Liked By
potatoes djiajgi
computer djiajgi
.........

Now, I'm trying to see people who like the same thing as you do, and am ordering them by the amount of things you have in common. Lets say you like potatoes and computers as well. It will display djiajgi, djiagi two times. I'd like it to appear only once like here http://sqlfiddle.com/#!2/b6f78/8 How would I go about doing this, so if I like computer and potatoes, it will display djiajgi only once? Code :

$people_like = mysqli_query ($link, "SELECT COUNT(user_liked_by) AS total, id, user_liked_by
FROM whatilike WHERE whats_liked LIKE '%$thing_liked%' && user_liked_by !='$user'
GROUP BY user_liked_by   
ORDER BY COUNT(user_liked_by) DESC; ");
2
Contributors
1
Reply
32
Views
3 Years
Discussion Span
Last Post by pzuurveen
0

maybe a subquery
see Click Here

    SELECT user_liked_by FROM ( 
        SELECT COUNT(user_liked_by) AS total, id, user_liked_by
        FROM whatilike WHERE whats_liked LIKE '%$thing_liked%' &&
        user_liked_by !='$user'
        ORDER BY COUNT(user_liked_by) DESC ) as names 
    GROUP BY user_liked_by;

not sure what this will do to the ORDER BY part

Edited by pzuurveen

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.