Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

consulta complexa de integração sql de amigo mútuo


event_id =1 e seu ID de usuário =1
SELECT u.*
FROM wp_fd_subscriptions AS s
JOIN wp_fd_users AS u 
   ON s.event_user_id = u.id
LEFT JOIN wp_fd_matches m1 
   ON m1.event_id = s.event_id 
   AND m1.event_user_id = 1
   AND m1.event_user_match_id = s.event_user_id
LEFT JOIN wp_fd_matches m2
   ON m1.event_id = m2.event_id 
   AND m2.event_user_id = m1.event_user_match_id
   AND m2.event_user_match_id = 1
WHERE s.event_id=1 AND u.id != 1 AND m2.id IS NULL;