Back to Editor

Solution: 34. Mismatch Between Channel Video Count and Dataset Video Count

Medium

Problem Detail:

Write a SQL query to find channels where the video_count in channels does not match the actual count of rows in videos.

Answer SQL Query:

SELECT c.channel_name,
       c.video_count AS channel_table_video_count,
       COUNT(v.video_id) AS dataset_video_count
FROM channels c
LEFT JOIN videos v
  ON c.channel_id = v.channel_id
GROUP BY c.channel_id, c.channel_name, c.video_count
HAVING c.video_count <> COUNT(v.video_id);
You can easily copy this solution, switch back to your editor tab, paste it, and run the SQL!