w3resource logo
SQL exercises

SQL Exercises, Practice, Solution - Query on Multiple Tables

>SQL [7 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts.]

1. Write a query to find those customers with their name and those salesmen with their name and city who lives in the same city.  Go to the editor

Sample table: salesman


Sample table: customer


Click me to see the solution with pictorial presentation

2. Write a SQL statement to find the names of all customers along with the salesmen who works for them.   Go to the editor

Sample table: customer


Sample table: salesman


Click me to see the solution with pictorial presentation

3. Write a SQL statement to display all those orders by the customers not located in the same cities where their salesmen live.   Go to the editor

Sample table: salesman


Sample table: customer


Sample table: orders


Click me to see the solution with pictorial presentation

4. Write a SQL statement that finds out each order number followed by the name of the customers who made the order.   Go to the editor

Sample table: orders


Sample table: customer


Click me to see the solution with pictorial presentation

5. Write a SQL statement that sorts out the customer and their grade who made an order. Each of the customers must have a grade and served by at least a salesman, who belongs to a city.    Go to the editor

Sample table: salesman


Sample table: customer


Sample table: orders


Click me to see the solution with pictorial presentation

6. Write a query that produces all customers with their name, city, salesman and commission, who served by a salesman and the salesman works at a rate of the commission within 12% to 14%.  Go to the editor

Sample table: salesman


Sample table: customer


Click me to see the solution with pictorial presentation

7. Write a SQL statement that produces all orders with the order number, customer name, commission rate and earned commission amount for those customers who carry their grade more than 200 and served by an existing salesman.  Go to the editor

Sample table: salesman


Sample table: customer


Sample table: orders


Click me to see the solution with pictorial presentation

Practice Online


More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.