Find Jobs
Hire Freelancers

MySQL query to show mutual friend suggestions

$10-30 USD

Complété
Publié il y a plus de 4 ans

$10-30 USD

Payé lors de la livraison
I am developing a website and have a query to show mutual friend suggestions, however the query isn't working perfectly. These friend suggestions will each have a button that when clicked will send a friend request to the user. The query that I have now shows mutual friend suggestions but is also displaying members who the user has already sent a request to. I do not want these people in the list, since a request has already been sent from the user viewing this list. `friends` table structure with sample data --------------------------------------- id, user_id, friend_id, status, date 149 1253343 1243522 0 1567894334 150 1243522 1253343 1 1567894334 151 1262117 1441712 2 1578241277 152 1441712 1262117 2 1578241277 When a user requests a friendship, two rows are inserted into the database, one for the requester and one for the requested. The requester row has a status of 1 while the requested row has a status of 0. Any status 2 means a confirmed friendship between two users. Here is the current query that needs to be modified to not show rows with a 0 or 1. In other words it shouldn't return users who have already sent or received a request from the user. The query should only return users who have not been sent a request yet from the user or have not sent one to this user. This database query stuff is a little over my head. I'm not sure if there is a query generator program that would help me with these complicated queries but for now I am requesting assistance from the developer community. Good luck! SELECT a.friend_id, COUNT(*) as relevance, GROUP_CONCAT(a.user_id ORDER BY a.user_id) as mutual_friends FROM friends a JOIN friends b ON ( b.friend_id = a.user_id AND [login to view URL] = 2 AND b.user_id = ".$_SESSION['user_id']." ) LEFT JOIN friends c ON ( c.friend_id = a.friend_id AND [login to view URL] = 2 AND c.user_id = ".$_SESSION['user_id']." ) WHERE [login to view URL] = 2 AND c.user_id IS NULL AND a.friend_id != ".$_SESSION['user_id']." GROUP BY a.friend_id ORDER BY RAND() LIMIT 5
N° de projet : 21182606

Concernant le projet

2 propositions
Projet à distance
Actif à il y a 5 ans

Cherchez-vous à gagner de l'argent ?

Avantages de faire une offre sur Freelancer

Fixez votre budget et vos délais
Soyez payé pour votre travail
Surlignez votre proposition
Il est gratuit de s'inscrire et de faire des offres sur des travaux
Décerné à :
Avatar de l'utilisateur
Hey, I will rewrite or modify your query to work correctly. Right now I’m on mobile so I can’t test your query but I have go through your table structure and query you have written. If I will get this job, then I will create table and will put some dummy data and will modify query. It can be done :) Regards, Nabeel Abid
$25 USD en 1 jour
5,0 (14 commentaires)
4,4
4,4
2 freelances proposent en moyenne $23 USD pour ce travail
Avatar de l'utilisateur
Hi, are you looking for an Real MySQL Expert? If yes, you're in RIGHT place and WELCOME! High-quality and Fast-delivery is promised! As a highly skilled full stack developer, I have rich experience in MySQL. I am very confident with my skills and I'd like to help your business by doing my best. My clients have never been frustrated with my work and I hope to make you one of them. I am able to work full time on your timezone and start working right away. Please confirm that I am one of the best fits for you and drop me a message for further discussion. Thanks and Best Regards, Pavel
$20 USD en 1 jour
4,9 (57 commentaires)
6,6
6,6

À propos du client

Drapeau de UNITED STATES
Bethel, United States
5,0
4
Méthode de paiement vérifiée
Membre depuis déc. 7, 2018

Vérification du client

Merci ! Nous vous avons envoyé un lien par e-mail afin de réclamer votre crédit gratuit.
Une erreur a eu lieu lors de l'envoi de votre e-mail. Veuillez réessayer.
Utilisateurs enregistrés Total des travaux publiés
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Chargement de l'aperçu
Permission donnée pour la géolocalisation.
Votre session de connexion a expiré et vous avez été déconnecté. Veuillez vous connecter à nouveau.