Knowee
Questions
Features
Study Tools

Write a query to display all the customers whose ID is 2001 below the salesperson ID of Mc Lyon.

Question

Write a query to display all the customers whose ID is 2001 below the salesperson ID of Mc Lyon.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a SQL query that would display all the customers whose ID is 2001 and are under the salesperson ID of Mc Lyon.

Please note that the exact query might vary depending on the structure of your database. I'm assuming you have a table named 'customers' with fields 'customer_id' and 'salesperson_id', and a table named 'salespersons' with fields 'salesperson_id' and 'salesperson_name'.

SELECT * 
FROM customers 
WHERE customer_id = 2001 
AND salesperson_id IN (
    SELECT salesperson_id 
    FROM salespersons 
    WHERE salesperson_name = 'Mc Lyon'
);

This query works in the following way:

  1. The subquery (the part in brackets) selects the ID of the salesperson named 'Mc Lyon' from the 'salespersons' table.
  2. The main query then selects all records from the 'customers' table where the 'customer_id' is 2001 and the 'salesperson_id' is the same as the one we found in the subquery.

This problem has been solved

Similar Questions

Write a query to retrieve the names of customers who have made multiple purchases and the count of their purchases.

Which Sql Statement Retrieves The First 5 Distinct Customer Names From A Table Named Customers?

Select all records from the Customers table, sort the result reversed alphabetically by the column City.

In a table for customers, the information about a single customer resides in a single:Question 6Answera.tableb.rowc.fieldd.column

From the following table, create a view 'newyorkstaff' to display details of salesmen who are based in New York.Sample table: salesman

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.