Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

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

From the following tables write a SQL query to display the customer name, customer city, grade, salesman, salesman city. The results should be sorted by ascending customer_id.

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

Practice Online


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

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: From the following tables write a SQL query to find those customers whose grade less than 300. Return cust_name, customer city, grade, Salesman, saleman city. The result should be ordered by ascending customer_id.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



SQL: Tips of the Day

SQL Server SELECT into existing table.

INSERT INTO dbo.TABLETWO
SELECT col1, col2
  FROM dbo.TABLEONE
 WHERE col3 LIKE @search_key

This assumes there's only two columns in dbo.TABLETWO - you need to specify the columns otherwise:

INSERT INTO dbo.TABLETWO
  (col1, col2)
SELECT col1, col2
  FROM dbo.TABLEONE
 WHERE col3 LIKE @search_key

Database: SQL Server

Ref: https://bit.ly/3y6tpA3