Error in selection query on social network requests [closed]

0
Hello, in my project I need to list the people and the requests received by the user, but when it comes to listing people, I need to list only those that have not sent or that the user has not sent requests, in this case, my friendship table save request status, 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;

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

    
asked by anonymous 29.11.2017 / 16:17

1 answer

0

I believe that the problem can be in your JOIN, you can try to use the 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 connection between the two tables.

    
29.11.2017 / 18:45