SQL Subquery Exercises: Find all the orders issued against the salesman who may works for customer whose id is 3007
SQL SUBQUERY : Exercise-3 with Solution
3. Write a query to find all the orders issued against the salesman who may works for customer whose id is 3007.
Sample table: Salesman
Sample table: Orders
SELECT * FROM orders WHERE salesman_id = (SELECT DISTINCT salesman_id FROM orders WHERE customer_id =3007);
Output of the Query:
ord_no purch_amt ord_date customer_id salesman_id 70002 65.26 2012-10-05 3002 5001 70005 2400.60 2012-07-27 3007 5001 70008 5760.00 2012-09-10 3002 5001 70013 3045.60 2012-04-25 3002 5001
Contribute your code and comments through Disqus.
Previous: Write a query to display all the orders for the salesman who belongs to the city London.
Next: Write a query to display all the orders which values are greater than the average order value for 10th October 2012.
What is the difficulty level of this exercise?