- Year not given
SQL: customers with account in Dharan
Short answer
Join Depositor and Account on acc_no, filter branch_name = 'Dharan', and select DISTINCT customer_name to avoid repeats. For example: SELECT DISTINCT d.customer_name FROM Depositor d JOIN Account a ON d.acc_no = a.acc_no WHERE a.branch_name = 'Dharan'.
Consider database schema: Account (acc_no, branch_name, balance) Branch (branch_name, branch_city, assets) Customer (customer_name, customer_street, customer_city) Loan (loan_no, branch_name, amount) Depositor (customer_name, acc_no) Borrower (customer_name, loan_no) List the name of customers who have acc in dharan branch.
The customer's name is in Depositor, the branch is in Account, and the two are linked by acc_no. So we join Depositor and Account and filter on the branch name. DISTINCT removes repeats when a customer has more than one account in the branch.
Using a join
SELECT DISTINCT d.customer_name
FROM Depositor d
JOIN Account a ON d.acc_no = a.acc_no
WHERE a.branch_name = 'Dharan';
Using a subquery
SELECT DISTINCT customer_name
FROM Depositor
WHERE acc_no IN (SELECT acc_no
FROM Account
WHERE branch_name = 'Dharan');
Relational algebra
Π customer_name (σ branch_name = 'Dharan' (Depositor ⋈ Account))
Sample (tested): Sujan holds accounts 1 and 2, both in Dharan, so the output is just Sujan once.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- SQL: customer name and address · Database Management System, chapter 3
- SQL: number of accounts per branch · Database Management System, chapter 3
- SQL: customer names beginning with su · Database Management System, chapter 3
- SQL: branch city with assets over 1000000 · Database Management System, chapter 3
- SQL: customer, branch, account details · Database Management System, chapter 3
- SQL: create tables for bank schema · Database Management System, chapter 3
- SQL: create and use bank database · Database Management System, chapter 3
- SQL: branches with avg balance over 50000 · Database Management System, chapter 3
- SQL: increase balances by 100% and 50% · Database Management System, chapter 3
- RA: count accounts in each branch · Database Management System, chapter 3