Question: Write a SQL query for: Who has the highest account balance? Display name and account balance in your SQL statement. create table account (account_number varchar(15)

Write a SQL query for:

Who has the highest account balance? Display name and account balance in your SQL statement.

create table account

(account_number varchar(15) not null,

branch_name varchar(15) not null,

balance number not null,

primary key(account_number));

create table branch

(branch_name varchar(15) not null,

branch_city varchar(15) not null,

assets number not null,

primary key(branch_name));

create table customer

(customer_name varchar(15) not null,

customer_street varchar(12) not null,

customer_city varchar(15) not null,

primary key(customer_name));

create table loan

(loan_number varchar(15) not null,

branch_name varchar(15) not null,

amount number not null,

primary key(loan_number));

create table depositor

(customer_name varchar(15) not null,

account_number varchar(15) not null,

primary key(customer_name, account_number),

foreign key(account_number) references account(account_number),

foreign key(customer_name) references customer(customer_name));

create table borrower

(customer_name varchar(15) not null,

loan_number varchar(15) not null,

primary key(customer_name, loan_number),

foreign key(customer_name) references customer(customer_name),

foreign key(loan_number) references loan(loan_number));

Here is the solution I have:

Premise:

In order to get the Name and accout balance we have to join three tables namely- account, depositor and customer.

select c.customer_name,a.balance from account a

join depositor d on d.account_numner=a.account_number

join customer c on c.customer_name=d.customer_name

where a.balance=

(Select Max(balance) from account a

join depositor d on d.account_numner=a.account_number

join customer c on c.customer_name=d.customer_name)

Is there an alternate solution to this problem?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!