w3resource
SQL exercises

SQL Subquery Exercises: Find all the customers whose id is 2001 bellow the salesman ID of Mc Lyon

SQL SUBQUERY: Exercise-7 with Solution

7. Write a query to display all the customers whose id is 2001 bellow the salesman ID of Mc Lyon.

Sample table : Customer


Sample table: Salesman


Sample Solution:

SELECT *
FROM customer
WHERE customer_id =
    (SELECT salesman_id -2001
     FROM salesman
     WHERE name = 'Mc Lyon');

Output of the Query:

customer_id	cust_name	city		grade	salesman_id
3005		Graham Zusi	California	200		5002

Explanation:

SQL Subqueries: Find all the customers whose id is 2001 bellow the salesman ID of Mc Lyon.

Practice Online


Inventory database model

Query Visualization:

Duration:

Query visualization of Find all the customers whose id is 2001 bellow the salesman ID of Mc Lyon - Duration

Rows:

Query visualization of Find all the customers whose id is 2001 bellow the salesman ID of Mc Lyon - Rows

Cost:

Query visualization of Find all the customers whose id is 2001 bellow the salesman ID of Mc Lyon - Cost

Contribute your code and comments through Disqus.

Previous: Write a query to display the commission of all the salesmen servicing customers in Paris.
Next: Write a query to count the customers with grades above New York's average.

What is the difficulty level of this exercise?