Skip to content
Advertisement

SQL query for EXCEPT or NOT IN

I’m new to SQL and I am trying to write a query on PostgreSQL to find the cust_ID and customer name of each customer at the bank who only has a loan at the bank, and no account.

The database schema is:

enter image description here

The results should have only these 3 customers:

enter image description here

My two attempts for this query are:

1)

Where my output is:

enter image description here

2)

output is: ERROR: operator does not exist: boolean = character varying LINE 3: where (borrower.cust_ID = customer.cust_ID) not in (select c… ^ HINT: No operator matches the given name and argument types. You might need to add explicit type casts. SQL state: 42883 Character: 117

Please help me get this query right! Thank you!

Advertisement

Answer

You can use EXISTS and NOT EXISTS to apply the logic that you want:

Or with IN and EXCEPT:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement