sql >> Base de Datos >  >> RDS >> Mysql

consulta compleja de integración de amigo mutuo sql

event_id =1 y su ID de usuario =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;