• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Datannum

Data science and web development for small business applications

  • Home
  • Microsoft Excel (spreadsheet) forum
    • Project: Analyze NYSE Data
  • SQL forum
    • Project: Query a Digital Music Store Database
  • Data Visualization
    • Project: Data Visualization Project using Tableau
    • IBM – Cognos Analytics/Planning Analytics/Cognos Controller with Watson
  • Linear Algebra forum
    • Curated resource to learn linear algebra
  • Hire Us/Support

Practice Quiz – Writing Queries: Is my JOIN usage correct?

Data Science/Business Analytics for Small Business Applications › Forums › SQL › Practice Quiz – Writing Queries: Is my JOIN usage correct?

Tagged: COUNT NULL in SQL, JOIN clause in SQL

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • April 22, 2022 at 9:13 am #140
    Admin
    Keymaster

      Here is the problem:

      All of the questions in this quiz pull from the open source Chinook Database. Please refer to the ER Diagram below and familiarize yourself with the table and column names to write accurate queries and get the appropriate answers.

      Find the first and last name of any customer who does not have an invoice. Are there any customers returned from the query?

      SQL Coursera Source: https://www.coursera.org/learn/sql-for-data-science

      Here is my tentative solution:

      SELECT customers.FirstName, customers.LastName, COUNT(invoices.invoiceId)
      FROM customers 
      JOIN invoices
      ON customers.CustomerId  = invoices.CustomerId
      GROUP BY Customers.CustomerId
      HAVING COUNT(invoiceId) IS NULL

      Seeking help as it seems my JOIN query might not be correct.


      Reply


      COUNT differs from the other aggregate functions, it never returns NULL. You need to use COUNT(...) = 0 instead.

      You’re trying to find any customers without invoices, but when you use an INNER JOIN it will only return customers that have rows in the invoice table. You need to use LEFT JOIN. https://www.tutorialspoint.com/sql/sql-left-joins.htm

      So revised query:

    • Author
      Posts
    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Log In

    Primary Sidebar

    profile for Techcosec Limited on Stack Exchange, a network of free, community-driven Q&A sites

    RSS CS50’s Introduction to Computer Science by Harvard University on Edx

    • Are pairs array and lock array similar in structure after execution of sort_pairs function? Is my base case okay with pairs array or do I need to modify with referencing to lock array? May 27, 2023
    • Recursion in lock-pairs function while drawing analogy with sum of natural numbers: What will be the recursive case May 25, 2023
    • Understanding recursive function with Tideman May 24, 2023
    • More explanation for the Tideman project May 22, 2023
    • Why the below for loop not leading to segmentation fault or garbage value and instead giving correct output May 21, 2023

    Subscribe via Email

    Enter your email address to subscribe and receive notifications of new posts by email.

    This website hosted on WP Engine

    Footer

    Editor’s choice

    Developer jobs remote full time
    • Terms
    • Privacy
    • Disclaimer