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

Stessa sottoquery utilizzata più volte in una singola query

Puoi scriverlo usando NOT EXISTS :

SELECT
    id, client_id, buyer_id
FROM relation AS r
WHERE NOT EXISTS
      ( SELECT 1 
        FROM <some_table> 
        WHERE (r.client_id = <some_id> OR r.buyer_id = <some_id>) 
          AND ...
      ) ;