0% found this document useful (0 votes)
9 views

Assignment on joins

The document contains a series of SQL queries designed to extract specific information from tables related to salespersons, customers, and orders. Each query addresses different requirements, such as finding customers in the same city as their salespersons, filtering orders by amount, and retrieving details based on commission rates. The queries utilize various SQL join operations to combine data from multiple tables effectively.

Uploaded by

reddysanthosh145
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Assignment on joins

The document contains a series of SQL queries designed to extract specific information from tables related to salespersons, customers, and orders. Each query addresses different requirements, such as finding customers in the same city as their salespersons, filtering orders by amount, and retrieving details based on commission rates. The queries utilize various SQL join operations to combine data from multiple tables effectively.

Uploaded by

reddysanthosh145
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment on joins

1. From the following tables write a SQL query to find the


salesperson and customer who belongs to same city. Return
Salesman, cust_name and city
select salesman.name,salesman.city "sales_city",customer.city
"customer_city",customer.customer_name from salesman
-> inner join
-> customer
-> on(salesman.salesman_id=customer.salesman_id);

2.From the following tables write a SQL query to find those orders where order
amount exists between 500 and 2000. Return ord_no, purch_amt, cust_name,
city.

select
orders.order_no,orders.puch_amt,customer.customer_name,custo
mer.city from orders inner join
-> customer on(orders.customer_id=customer.customer_id)
-> where puch_amt between 500 and 2000;
3.From the following tables write a SQL query to find the salesperson(s) and
the customer(s) he handle. Return Customer Name, city, Salesman,
commission.

select
customer.customer_name,customer.city,salesman.name,salesman.c
ommission from customer
-> inner join
-> salesman on (customer.salesman_id=salesman.salesman_id);
4.From the following tables write a SQL query to find those salespersons who
received a commission from the company more than 12%. Return Customer
Name, customer city, Salesman, commission.
select
customer.customer_name,customer.city,salesman.name,salesman.commissio
n from customer
-> inner join
-> salesman on (customer.salesman_id=salesman.salesman_id)
-> where commission>0.12;
5.From the following tables write a SQL query to find those salespersons do
not live in the same city where their customers live and received a commission
from the company more than 12%. Return Customer Name, customer city,
Salesman, salesman city, commission.
select
customer.customer_name,customer.city,salesman.name,salesman.city,salesm
an.commission from customer
-> inner join
-> salesman on(customer.salesman_id=salesman.salesman_id)
-> where salesman.city<>customer.city and commission>0.12;
6.From the following tables write a SQL query to find the details of an order.
Return ord_no, ord_date, purch_amt, Customer Name, grade, Salesman,
commission.
select
orders.order_no,orders.order_date,orders.puch_amt,customer.customer_nam
e,customer.grade,salesman.name,salesman.commission from orders
-> join
-> customer on(orders.customer_id=customer.customer_id)
-> join salesman on(orders.salesman_id=salesman.salesman_id);
7.Write a SQL statement to make a join on the tables salesman, customer and
orders in such a form that the same column of each table will appear once and
only the relational rows will come
SELECT *
-> FROM orders
-> NATURAL JOIN customer
-> NATURAL JOIN salesman;

8.From the following tables write a SQL query to display the cust_name,
customer city, grade, Salesman, salesman city. The result should be ordered
by ascending on customer_id.
select
customer.customer_name,customer.city,customer.grade,salesman.name,sale
sman.city from customer
-> inner join salesman on(customer.salesman_id=salesman.salesman_id)
order by customer_id;

9.From the following tables write a SQL query to find those customers whose
grade less than 300. Return cust_name, customer city, grade, Salesman,
saleman city. The result should be ordered by ascending customer_id

select
customer.customer_name,customer.city,customer.grade,salesman.n
ame,salesman.city from customer
-> inner join salesman
on(customer.salesman_id=salesman.salesman_id)
-> where grade<300 order by customer_id;

10.Write a SQL statement to make a report with customer name, city, order
number, order date, and order amount in ascending order according to the
order date to find that either any of the existing customers have placed no
order or placed one or more orders.

select
customer.customer_name,customer.city,orders.order_no,orders.ord
er_date,orders.puch_amt from customer
-> left join orders on(orders.customer_id=customer.customer_id)
order by order_date;

You might also like