How to select all records from a table that do not exist in a union of two another tables in mysql

I want to return all records that do not exist in an union of two other tables but when i try to enclose the result of the union the workbench returns a syntax error. What i'm doing wrong?

SELECT TransactionID
from transactions 
where transactionid not in

(
(select distinct Transactionid
from transactionsdebits 
where   accountid like '81%')

union

(select distinct TransactionID
from transactionscredits
where accountid like '81%')
)
;

Upvotes: 0

Views: 30

Answers (1)

Fahmi
Fahmi

Reputation: 37473

You can try below -

    SELECT TransactionID
    from transactions 
    where transactionid not in ( select transactionid from
     (
       select distinct Transactionid
       from transactionsdebits 
       where   accountid like '81%'
       union
       select distinct TransactionID
       from transactionscredits
       where accountid like '81%'
     )
   A)

Upvotes: 1

Related Questions