w3resource
SQL exercises

SQL Exercises: Make a list in ascending order for the customer who works either through a salesman or by own

SQL JOINS: Exercise-8 with Solution

Write a SQL statement to make a list in ascending order for the customer who works either through a salesman or by own.

Sample table: customer


Sample table: salesman


Sample Solution:

SELECT a.cust_name,a.city,a.grade, 
b.name AS "Salesman",b.city 
FROM customer a 
LEFT JOIN salesman b 
ON a.salesman_id=b.salesman_id 
order by a.customer_id;

Output of the Query:

cust_name	city		grade	Salesman	city
Brad Guzan	London			Pit Alex	London
Nick Rimando	New York	100	James Hoog	New York
Jozy Altidor	Moscow		200	Paul Adam	Rome
Fabian Johnson	Paris		300	Mc Lyon		Paris
Graham Zusi	California	200	Nail Knite	Paris
Brad Davis	New York	200	James Hoog	New York
Julian Green	London		300	Nail Knite	Paris
Geoff Cameron	Berlin		100	Lauson Hen	San Jose

Explanation:

Syntax of a list in ascending order

Pictorial presentation :

Result of a list in ascending order

Query Visualization:

Duration:

Query visualization of Make a list in ascending order for the customer who works either through a salesman or by own - Duration

Rows:

Query visualization of Make a list in ascending order for the customer who works either through a salesman or by own - Rows

Cost:

Query visualization of Make a list in ascending order for the customer who works either through a salesman or by own - Cost

 

Practice Online


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

Previous: Write a SQL statement to make a join on the tables salesman, customer and orders in such a form that the same column of each table will appear once and only the relational rows will come.
Next: Write a SQL statement to make a list in ascending order for the customer who holds a grade less than 300 and works either through a salesman or by own.

What is the difficulty level of this exercise?



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