w3resource
SQL exercises

SQL Subquery Exercises: Display the names and numbers of all salesmen who had more than one customer

SQL SUBQUERY: Exercise-11 with Solution

11. Write a query to find the name and numbers of all salesmen who had more than one customer.

Sample table: customer


Sample table: salesman


Sample Solution:

SELECT salesman_id,name 
FROM salesman a 
WHERE 1 < 
    (SELECT COUNT(*) 
     FROM customer 
     WHERE salesman_id=a.salesman_id);

Output of the Query:

salesman_id	name
5001		James Hoog
5002		Nail Knite

Explanation:

SQL Subqueries: Display the names and numbers of all salesmen who had more than one customer.

Practice Online


Inventory database model

Query Visualization:

Duration:

Query visualization of Display the names and numbers of all salesmen who had more than one customer - Duration

Rows:

Query visualization of Display the names and numbers of all salesmen who had more than one customer - Rows

Cost:

Query visualization of Display the names and numbers of all salesmen who had more than one customer - Cost

Contribute your code and comments through Disqus.

Previous: Write a query to display all the customers with orders issued on date 17th August, 2012.
Next: Write a query to find all orders with order amounts which are above-average amounts for their customers.

What is the difficulty level of this exercise?