Error in selection query about social network requests

Asked

Viewed 37 times

0

Hello, in my project I need to list the people and requests received by the user, but when listing people, I need to list only those who did not submit or that the user did not submit requests, in case, my friendship table keeps the status of the request, being 0 for pending

SELECT * FROM tbUsuario user JOIN tbAmizade am, tbGenMus gen WHERE NOT
((am.fkUsuarioSend = user.usId AND am.fkUsuarioReceive = {$_SESSION['usuario']['usId']})
OR (am.fkUsuarioSend = {$_SESSION['usuario']['usId']} AND am.fkUsuarioReceive = user.UsId))
AND NOT user.usId = {$_SESSION['usuario']['usId']} AND gen.idGenMus = user.fkGenMus;

created this query and worked for a moment, but when the user sent more than one request, the query started to duplicate the results and put the ones that should not appear.

  • Clarify your specific issue or add other details to highlight exactly what you need. The way it’s written here, it’s hard to know exactly what you’re asking. See the How to Ask page for help clarifying this question.

1 answer

0


I believe the problem may be in your JOIN, you can try using ON to specify the JOIN condition.

SELECT * 
FROM tbUsuario user 
     JOIN tbAmizade am ON user.id = am.user_id, 
     tbGenMus gen 
[...]

Without using ON, your JOIN will be equivalent to a CROSS JOIN, resulting in the Cartesian product of the link between the two tables.

Browser other questions tagged

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