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

bookChallenge: Unmatched Records Report

Tarea

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;

Solución

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 6
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

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

Desliza para mostrar el menú

Tarea

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;

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 6
single

single

some-alt