Reputation: 13
SQL query, find the user that does not have bank_account
I have two tables, the first one is table bank_customer, and the other is table user. The table of bank_customer has many columns, including user_id and bank_account. in table user, I have column id.
not every user has bank_account. so I want to query, users that do not have a bank_account, but it gets hard.
SELECT * FROM users, bank_customers
WHERE NOT users.id=bank_customers.user_id
so how can I query in SQL with this case?
and how to logic that case? for the next case I can find out by myself.
Upvotes: 0
Views: 268
Reputation: 4383
There are a few ways to go about that, but the simplest way would probably be using IN
:
SELECT *
FROM users
WHERE id NOT IN (
SELECT user_id
FROM bank_customers
)
Upvotes: 1