Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Challenge: Unmatched Records Report | Core Join Types and Their Applications
SQL Joins in Depth

bookChallenge: Unmatched Records Report

Compito

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;

Soluzione

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 6
single

single

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

Suggested prompts:

Can you explain that in more detail?

What are the main benefits or drawbacks?

Can you give me an example?

close

bookChallenge: Unmatched Records Report

Scorri per mostrare il menu

Compito

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;

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 6
single

single

some-alt