#C14812. Left Outer Join: Merging Customers and Orders
Left Outer Join: Merging Customers and Orders
Left Outer Join: Merging Customers and Orders
In this problem, you are given two tables: a Customers table and an Orders table. The Customers table contains information about customers including \(customerId\), name, and age, and the Orders table contains information about orders, including \(orderId\), \(customerId\), product, and orderDate. Your task is to perform a left outer join on these tables using the \(customerId\). That means for each customer, if there are corresponding orders, output each order on a separate line; if a customer has no orders, output the customer information with NULL
values for the order fields.
inputFormat
The input is given as follows:
- The first line contains two integers \(n\) and \(m\), representing the number of customers and orders, respectively.
- The next \(n\) lines each contain three entries separated by spaces:
customerId
(a string without spaces),name
(a string without spaces), andage
(an integer). - The following \(m\) lines each contain four entries separated by spaces:
orderId
(a string without spaces),customerId
(a string),product
(a string), andorderDate
(a date in YYYY-MM-DD format).
outputFormat
Output the merged table with each row displaying the following six fields, separated by a single space:
customerId
name
age
orderId
product
orderDate
If a customer does not have any corresponding orders, print NULL
for the orderId
, product
, and orderDate
fields.
3 3
1 Alice 25
2 Bob 30
3 Charlie 35
101 1 Book 2021-01-01
102 2 Laptop 2021-01-02
103 2 Pen 2021-01-03
1 Alice 25 101 Book 2021-01-01
2 Bob 30 102 Laptop 2021-01-02
2 Bob 30 103 Pen 2021-01-03
3 Charlie 35 NULL NULL NULL
</p>