SQL Exercises 7 — Joins

1. From the customer and salesman tables, find the salesperson and customer who belongs to same city. Return Salesman, cust_name and city.

2. From the customer and orders tables, find those orders where order amount exists between 500 and 2000. Return ord_no, purch_amt, cust_name, city.

3. From the customer and salesman tables, find the salesperson(s) and the customer(s) he handle. Return Customer Name, city, Salesman, commission.

4. From the customer and salesman tables, find those salespersons who received a commission from the company more than 12%. Return Customer Name, customer city, Salesman, commission.

5. From the customer and salesman tables, 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.

6. From the customer, salesman and orders tables, find the details of an order. Return ord_no, ord_date, purch_amt, Customer Name, grade, Salesman, commission.

7. 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.

8. From the customer and salesman tables, display the cust_name, customer city, grade, Salesman, salesman city. The result should be ordered by ascending on customer_id.

9. From the customer and salesman tables, 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.

10. 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.

11. Make a report with customer name, city, order number, order date, order amount salesman name and commission to find that either any of the existing customers have placed no order or placed one or more orders by their salesman or by own.

12. Make a list in ascending order for the salesmen who works either for one or more customer or not yet join under any of the customers.

13. From the customer, salesman and orders tables, list all salespersons along with customer name, city, grade, order number, date, and amount.

14. Make a list for the salesmen who either work for one or more customers or yet to join any of the customer. The customer may have placed, either one or more orders on or above order amount 2000 and must have a grade, or he may not have placed any order to the associated supplier.

15. Make a report with customer name, city, order no. order date, purchase amount for those customers from the existing list who placed one or more orders or which order(s) have been placed by the customer who is not on the list.

16. Combine each row of salesman table with each row of customer table.

17. Make a cartesian product between salesman and customer i.e. each salesman will appear for all customer and vice versa for those salesmen who must belong a city which is not the same as his customer and the customers should have an own grade.

18. From the company master and item master tables, select all rows from both participating tables as long as there is a match between pro_com and com_id.

19. Display the item name, price, and company name of all the products.

20. From the company master and item master tables, calculate the average price of items of each company. Return average value and company name.

21. From the company master and item master tables, calculate and find the average price of items of each company higher than or equal to Rs. 350. Return average value and company name.

22. From the company master and item master tables, find the most expensive product of each company. Return pro_name, pro_price and com_name.

23. From the employee department and employee details tables, display all the data of employees including their department.

24. From the employee department and employee details tables, display the first name and last name of each employee, along with the name and sanction amount for their department.

25. From the employee department and employee details tables, find the departments with a budget more than Rs. 50000 and display the first name and last name of employees.

26. From the employee department and employee details tables, find the names of departments where more than two employees are working. Return dpt_name.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store