w3resource

SQL Exercises: Short out the customer and their grade who made an order

SQL Query on Multiple Tables: Exercise-5 with Solution

From the following tables, write a SQL query to find those customers where each customer has a grade and served by at least a salesperson who belongs to a city. Return cust_name as "Customer", grade as "Grade".

Sample table: salesman


Sample table: customer


Sample table: orders


Sample Solution:

SELECT customer.cust_name AS "Customer",
customer.grade AS "Grade"
FROM orders, salesman, customer
WHERE orders.customer_id = customer.customer_id
AND orders.salesman_id = salesman.salesman_id
AND salesman.city IS NOT NULL
AND customer.grade IS NOT NULL;

Output of the query:

Customer	Grade
Nick Rimando	100
Geoff Cameron	100
Brad Davis	200
Nick Rimando	100
Fabian Johnson	300
Geoff Cameron	100
Jozy Altidor	200
Nick Rimando	100
Graham Zusi	200
Graham Zusi	200
Julian Green	300

Explanation :

Syntax of short out the customer and their grade who made an order

Pictorial presentation :

Result of customer and their grade who made an order

Practice Online


Query Visualization:

Duration:

Query visualization of Short out the customer and their grade who made an order - Duration

Rows:

Query visualization of Short out the customer and their grade who made an order - Rows

Cost:

Query visualization of Short out the customer and their grade who made an order - Cost

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: From the following tables, write a SQL query to find those orders made by customers. Return order number, customer name.
Next: From the following table, write a SQL query to find those customers who served by a salesperson and the salesperson works at the commission in the range 12% to 14% (Begin and end values are included.). Return cust_name AS "Customer", city AS "City".

What is the difficulty level of this exercise?