Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge: Unmatched Records Report | Core Join Types and Their Applications
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
SQL Joins in Depth

bookChallenge: Unmatched Records Report

Uppgift

Swipe to start coding

Write a SQL query to produce a report of all customers and all orders, showing unmatched records and matched pairs using a FULL OUTER JOIN.

Follow these steps:

  • Use a FULL OUTER JOIN to join the customers and orders tables on the customer_id field;
  • In your SELECT clause, include:
    • The customer_id from the customers table;
    • The name column from the customers table, but alias it as customer_name;
    • The order_id from the orders table;
    • The order_date from the orders table;
  • Add a column named match_status that uses a CASE statement with the following logic:
    • If order_id is NULL, set the value to 'Customer without orders';
    • If customer_id is NULL, set the value to 'Order without customer';
    • Otherwise, set the value to 'Matched';
  • Order the results so that all unmatched records (where either customer_id or order_id is NULL) appear before the matched records;

Lösning

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 6
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

close

bookChallenge: Unmatched Records Report

Svep för att visa menyn

Uppgift

Swipe to start coding

Write a SQL query to produce a report of all customers and all orders, showing unmatched records and matched pairs using a FULL OUTER JOIN.

Follow these steps:

  • Use a FULL OUTER JOIN to join the customers and orders tables on the customer_id field;
  • In your SELECT clause, include:
    • The customer_id from the customers table;
    • The name column from the customers table, but alias it as customer_name;
    • The order_id from the orders table;
    • The order_date from the orders table;
  • Add a column named match_status that uses a CASE statement with the following logic:
    • If order_id is NULL, set the value to 'Customer without orders';
    • If customer_id is NULL, set the value to 'Order without customer';
    • Otherwise, set the value to 'Matched';
  • Order the results so that all unmatched records (where either customer_id or order_id is NULL) appear before the matched records;

Lösning

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 6
single

single

some-alt