1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[SQL] SQL Query: How to return products that don't have reviews

Discussão em 'Outras Linguagens' iniciado por Stack, Setembro 10, 2021.

  1. Stack

    Stack Membro Participativo

    I have a table of reviews and a table of products. E.g. the following dummy data:



    I want to return only the products that do not have any reviews.

    My SQL code is currently

    SELECT *
    FROM products
    LEFT JOIN reviews
    ON products.id = reviews.product_id
    WHERE reviews.content IS NULL;

    As each product has multiple reviews, only some of which are null, I'm concerned that this approach returns false negatives (i.e. I don't want products that are associated with some empty reviews among other completed reviews, I only want products for which no reviews exist at all). Do I need to add a HAVING clause?

    Thanks much for your help in advance.

    Continue reading...

Compartilhe esta Página