w3resource
SQL exercises

SQL Subquery Exercises: Display the rows of all salesmen who have customers with more than one orders

SQL SUBQUERY: Exercise-18 with Solution

18. Write a query that extract the rows of all salesmen who have customers with more than one orders.

Sample table: Salesman


Sample table: Orders


Sample table: Customer


Sample Solution:

SELECT * 
FROM salesman a 
WHERE EXISTS     
   (SELECT * FROM customer b     
    WHERE a.salesman_id=b.salesman_id     
	 AND 1<             
	     (SELECT COUNT (*)              
		  FROM orders             
		  WHERE orders.customer_id =            
		  b.customer_id));

Sample Output:

salesman_id	name	city		commission
5001		James Hoog	New York	0.15
5002		Nail Knite	Paris		0.13
5003		Lauson Hen	San Jose	0.12

Practice Online


Inventory database model

Query Visualization:

Duration:

Query visualization of Display the rows of all salesmen who have customers with more than one orders - Duration

Rows:

Query visualization of Display the rows of all salesmen who have customers with more than one orders - Rows

Cost:

Query visualization of Display the rows of all salesmen who have customers with more than one orders - Cost

Contribute your code and comments through Disqus.

Previous: Write a query to find all the salesmen who worked for only one customer.
Next: Write a query to find salesmen with all information who lives in the city where any of the customers lives.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming