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: Find out customers who made the order

SQL Query on Multiple Tables: Exercise-4 with Solution

From the following tables, write a SQL query to locate the orders made by customers. Return order number, customer name.

Sample table: orders


Sample table: customer


Sample Solution:

SELECT orders.ord_no, customer.cust_name
FROM orders, customer
WHERE orders.customer_id = customer.customer_id; 

Output of the query:

ord_no	cust_name
70009	Brad Guzan
70002	Nick Rimando
70004	Geoff Cameron
70005	Brad Davis
70008	Nick Rimando
70010	Fabian Johnson
70003	Geoff Cameron
70011	Jozy Altidor
70013	Nick Rimando
70001	Graham Zusi
70007	Graham Zusi
70012	Julian Green

Relational Algebra Expression:

Relational Algebra Expression: Find out customers who made the order.

Relational Algebra Tree:

Relational Algebra Tree: Find out customers who made the order.

Explanation:

Syntax to find out customers who made the order

Pictorial presentation :

Result of customers who made the order

Practice Online


Query Visualization:

Duration:

Query visualization of Find out customers who made the order - Duration

Rows:

Query visualization of Find out customers who made the order - Rows

Cost:

Query visualization of Find out customers who made the 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 salespeople who generated orders for their customers but not located in the same city. Return ord_no, cust_name, customer_id (orders table), salesman_id (orders table).
Next: 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".

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