w3resource
SQL exercises

SQL Exercises: Find the salesmen and customers with their name and cities, who belongs to the same city

SQL JOINS: Exercise-1 with Solution

Write a SQL statement to prepare a list with salesman name, customer name and their cities for the salesmen and customer who belongs to the same city.

Sample table: salesman


Sample table: customer


Sample Solution:

SELECT salesman.name AS "Salesman",
customer.cust_name, customer.city 
FROM salesman,customer 
WHERE salesman.city=customer.city;

Output of the Query:

Salesman	cust_name	city
James Hoog	Nick Rimando	New York
James Hoog	Brad Davis	New York
Pit Alex	Julian Green	London
Mc Lyon		Fabian Johnson	Paris
Nail Knite	Fabian Johnson	Paris
Pit Alex	Brad Guzan	London

Explanation:

Syntax of prepare a list with salesman name, customer name and their cities for the salesmen and customer who belongs to same city

Pictorial presentation:

Result of prepare a list with salesman name, customer name and their cities for the salesmen and customer who belongs to same city

Query Visualization:

Duration:

Query visualization of Find the salesmen and customers with their name and cities, who belongs to the same city - Duration

Rows:

Query visualization of Find the salesmen and customers with their name and cities, who belongs to the same city - Rows

Cost:

Query visualization of Find the salesmen and customers with their name and cities, who belongs to the same city - Cost

 

Practice Online


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

Previous: SQL JOINS Exercises Home
Next: Write a SQL statement to make a list with order no, purchase amount, customer name and their cities for those orders which order amount between 500 and 2000.

What is the difficulty level of this exercise?



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