Mysql
 sql >> Database >  >> RDS >> Mysql

query complessa di integrazione sql amico comune

event_id =1 e il tuo ID utente =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;