w3resource

SQL exercises on movie Database: Find the names of all reviewers who have ratings with a NULL value

SQL movie Database: Subquery Exercise-8 with Solution

8. From the following table, write a SQL query to find those reviewers who have not given a rating to certain films. Return reviewer name.

Sample table: reviewer


Sample table: rating


Sample Solution:

SELECT DISTINCT rev_name 
FROM reviewer 
WHERE rev_id IN (
SELECT rev_id 
FROM rating 
WHERE rev_stars IS NULL);

Sample Output:

            rev_name
--------------------------------
 Neal Wruck
 Scott LeBrun
(2 rows)

Code Explanation:

The said query in SQL which selects distinct reviewer names from the 'reviewer' table where the corresponding reviewer IDs have at least one review with a null rating in the 'Rating' table. The results are ordered by reviewer name in ascending order.
The query uses a subquery to find the reviewer IDs with null ratings, and then selects the distinct reviewer names corresponding to those IDs. The "DISTINCT" keyword ensures that only unique reviewer names are returned.

Practice Online


Movie database model

Query Visualization:

Duration:

Query visualization of Find the names of all reviewers who have ratings with a NULL value - Duration

Rows:

Query visualization of Find the names of all reviewers who have ratings with a NULL value - Rows

Cost:

Query visualization of Find the names of all reviewers who have ratings with a NULL value - Cost

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: From the following table, write a SQL query to find those movies, which have no ratings. Return movie title.
Next: From the following tables, write a SQL query to find those movies, which reviewed by a reviewer and got a rating. Sort the result-set in ascending order by reviewer name, movie title, review Stars. Return reviewer name, movie title, review Stars.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.

SQL: Tips of the Day

What is the best way to paginate results in SQL Server?

SELECT  *
FROM    ( SELECT    ROW_NUMBER() OVER ( ORDER BY OrderDate ) AS RowNum, *
          FROM      Orders
          WHERE     OrderDate >= '1980-01-01'
        ) AS RowConstrainedResult
WHERE   RowNum >= 1
    AND RowNum < 20
ORDER BY RowNum

Database: SQL Server

Ref: https://bit.ly/3MGrNlk

 





We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook